On Tue, Jan 10, 2006 at 10:47:50PM +0100 or thereabouts, Raoul Ripmeester wrote:
> Hello all,
>
> 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>
>
This looks like fixed width data to me.
> 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>){
> ($date,$time,$type,$subtype,$node,$username,$ID, $term) =
> split(/ /,$_) ;
> 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.
>
I had to do something like this a while back ... had the same problem. A
friend of mine introduced me to a different function --> unpack.
Unfortuneately ..... I don't remember the exact syntax.
> 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>
>
--
Casey Cichon
[EMAIL PROTECTED]
Never ascribe to malice that which could merely be incompetence.
--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
<http://learn.perl.org/> <http://learn.perl.org/first-response>