> -----Original Message-----
> From: Marvin Bonilla [mailto:[EMAIL PROTECTED]] 
> Sent: Tuesday, July 24, 2001 1:54 PM
> To: [EMAIL PROTECTED]
> Subject: Problem with scan fields using split
> 
> 
> Hello
> 
> Certainly I have already new in program with perl , so I need 
> help with a log scan program, that extract a field 
> information from a log file and get some fileds in order to 
> use in another program. the log fields looks like this:
> 
> Jul 24 11:37:59.878 [13001] (v3.1.2) POP login by user 
> "conhosvp" at (m32.ibw.com.ni) 216.226.201.71 Jul 24 
> 11:37:59.932 [13002] (v3.1.2) POP login by user "icade" at 
> (mdig76.ibw.com.ni) 64.110.119.80
> 
> If you see the digits 24 are the second field using split(/ 
> /,$s) where the white space is the separator, the problems 
> begin when the digit is just one, thats mean from 1 to 9, the 
> field become third because the split take a white space as 
> the second field, that situation results in that i need to 
> change the program every time the date change from 1 to 2 
> digits to read correctly the fields.
> 
> Is there a solutions to avoid this situation with the split 
> function?? Thank you for your help.

Use split(' ', $s) or split(/\s+/, $s) instead of split(/ /, $s).

Using / / as your delimiter pattern means to treat each blank as a
delimiter. So "Jul  1" is treated as "Jul", "", "1". The /\s+/ pattern
treats any sequence of one or more whitespace chars as the delimiter (you
could also use / +/ to just use spaces and not other whitespace chars). Per
the documentation, a delimiter of a single space as a string (not a regex)
is the same as delimiting on sequences of whitespace.

   perldoc -f split

-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to