|
|
|||||||||
|
|||||||||
| |||||||||
|
|
|
| |||||||||
![]() |
|
|
«
Previous Thread
|
Next Thread
»
|
Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
|
|
Stay one step ahead of the competition. Evaluate and give feedback
on some of the hottest web development tools on the market today.
Make your opinion heard! Click
Here
|
|
#1
|
|||
|
|||
|
Hi all,
I am trying to chunk my files into strings. It's normally done by: open (FILE,'<filename'); while (<FILE> ) { } But this time I don't want to break line like that. My record may be on more than 1 line. At the end of each record I have a special string '~~REC~~' I want to break my file by this '~~REC~~' string. I read the Perl book, it mentions about the variable $: But I try to change it $:='~~REC~~', it doesn't work. The book says the default value is $:=' n-' Any suggestion please! Thank you very much for your help. Nam. |
|
#2
|
||||
|
||||
|
<BLOCKQUOTE><font size="1" face="Verdana,Arial,Helvetica">quote:</font><HR>Originally posted by NamHN:
My record may be on more than 1 line. At the end of each record I have a special string '~~REC~~' I want to break my file by this '~~REC~~' string.[/quote] If I understand correctly, you want to break this file into individual records. If so, what you want to do is set the 'Input Record Separator', or $/ to '~~REC~~': $/ = '~~REC~~'; open FILE, "<$file" or die "cannot open file $file: $!n"; while (defined($rec = <FILE> )) { . . . Now $rec should hold the contents of a record. Hope this helps... |
![]() |
| Viewing: Dev Shed Forums > Programming Languages > Perl Programming > Using $: to change break line character |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|
|
|