On 6/25/06, David Gilden <[EMAIL PROTECTED]> wrote:
I am not sure I have the syntax quite right here, any suggestions would be welcome.
You can find the syntax for substr, as with any of Perl's built-in functions, in the perlfunc manpage. You should be able to use this command from the command line to see the documentation on substr: perldoc -f substr
$line = "Friday, June 23, 2006 12:30 PM" ; $last_updated = substr($line, 0, (length($line) -9)); # remove the time # part of time stamp # the above line is throwing an error
What error? Perl's error and warning messages have documentation as well; check out the perldiag manpage. If you have any trouble finding the message in there, the diagnostics module can help. It looks as if you may be manipulating date-and-time data. If that's your goal, and you don't want to write all the special cases yourself, there are many helpful modules on CPAN. When indexing into a string with substr(), the position nine characters from the end of the string can be represented by -9, for convenience. That means that one way to delete the last nine characters in a string would be to assign to substr: substr($some_str, -9) = ""; # replace last 9 with empty str I'm sure somebody will show you how to do something similar to what you're doing with a regular expression. But I'm not certain that I understand what you're doing well enough to write a pattern that would be correct, even though that would be the "weapon of choice" for many Perl programmers. One big reason is that a pattern can easily adapt to flexible data formats, such as a timestamp which may be written in many different ways. Hope this helps! --Tom Phoenix Stonehenge Perl Training -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] <http://learn.perl.org/> <http://learn.perl.org/first-response>