> -----Original Message----- > From: Raoul Ripmeester [mailto:[EMAIL PROTECTED] > Sent: Tuesday, January 10, 2006 4:48 PM > To: beginners@perl.org > Subject: Splitting file > > Hello all,
Hello, > > I am a newbe so please bare with me : > > I am trying to split lines of a file into variables so I can do some > sorting and other stuff with this. Now my script is working but the > split is giving me problems. I am splitting on the space character, but > the line(s) can contain multiple spaces. Underneath a few sample lines > that I am trying to split. > > <logfile> > > 7-NOV-2005 09:24:00.56 PRIVILEGE PRVAUD_SUCCESS SMC8 SMCMAN > 000002DF TXA4: > 7-NOV-2005 09:24:24.36 PRIVILEGE PRVAUD_SUCCESS SMC8 SMCMAN > 000002DF TXA4: > 7-NOV-2005 09:25:16.44 PRIVILEGE PRVAUD_SUCCESS SMC8 SMCMAN > 000002DF TXA4: > 7-NOV-2005 09:25:42.22 PRIVILEGE PRVAUD_SUCCESS SMC8 SMCMAN > 000002DF TXA4: > 7-NOV-2005 09:27:53.48 PRIVILEGE PRVAUD_SUCCESS SMC8 SMCMAN > 000002DF TXA4: > 7-NOV-2005 09:29:51.32 LOGOUT LOCAL SMC8 SMCMAN > 000002DF _TXA4: > 7-NOV-2005 09:46:13.94 LOGIN LOCAL SMC8 SMCMAN > 000002E0 _TXA4: > </logfile> > > And here is a part of the code I am using ( the print statements are > just to test the splitting ) : > > <code> > > open (FILE, $file ) || die ("open of $file failed $! \n") ; > while (<FILE>){ To match one or more spaces, your regex should be: /\s+/ This: > ($date,$time,$type,$subtype,$node,$username,$ID, $term) = > split(/ /,$_) ; becomes: ($date,$time,$type,$subtype,$node,$username,$ID, $term) = split(/\s+/,$_) ; ry > print "date = $date \t time = $time \t type = $type \n" ; > print "subtype = $subtype \t node = $ node \t username = > $username \n " ; > print "ID = $ID \t term = $term \n " ; > } > > </code> > > How can I make the split to work with one or multiple space. I tried to > split on / .*/ But that will put the whole line in the first variable, > so what am I missing. > > Thanks and best regards, > > Raoul. > > -- > Censorship cannot eliminate evil, it can only kill freedom. > > > -- > To unsubscribe, e-mail: [EMAIL PROTECTED] > For additional commands, e-mail: [EMAIL PROTECTED] > <http://learn.perl.org/> <http://learn.perl.org/first-response> > -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] <http://learn.perl.org/> <http://learn.perl.org/first-response>