On Sun, Jun 25, 2006 at 01:16:13PM -0500, David Gilden wrote: > Hello, > > I am not sure I have the syntax quite right here, any suggestions would be > welcome. > > > $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
It seems to work fine for me. I tested the following: #!/usr/bin/perl use strict; use warnings; my $line = 'Friday, June 23, 2006 12:30 PM'; print substr($line, 0, (length($line) -9)); The following was my output: Friday, June 23, 2006 No problems, if I properly understand what you're trying to accomplish. I do have some suggestions, though: * Use single-quotes for strings that don't require interpolation. * Use lexical variable declarations. * Use the strict and warnings pragmas to troubleshoot script bugs. The bit about lexical variable declarations is why I added "my" to the assignment line, and the bit about string interpolation is why I replaced instances of " with '. The substr() function takes three arguments (as you seem to have discovered already): the first is a string, the second is a starting point, and the third is an ending point. It returns the parts of the string that fit between those points. The starting point counts from the start of the string, and the ending point counts from the end of the string. A fourth argument can be used for operations that aren't relevant here. The end result is that you seem to have used substr() exactly the way it's meant to be used. perl -le "print substr 'Just another Perl hacker', 0, -2" -- CCD CopyWrite Chad Perrin [ http://ccd.apotheon.org ] "The first rule of magic is simple. Don't waste your time waving your hands and hopping when a rock or a club will do." - McCloctnick the Lucid -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] <http://learn.perl.org/> <http://learn.perl.org/first-response>