SunQuest
           Perl Programming
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
User Name:
Password:
Remember me
Go Back   Dev Shed ForumsProgramming LanguagesPerl Programming

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread Dev Shed Forums Sponsor:
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  
Old November 10th, 2000, 09:00 AM
NamHN NamHN is offline
Junior Member
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Oct 2000
Posts: 0 NamHN User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
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.

Reply With Quote
  #2  
Old November 10th, 2000, 12:52 PM
vpopper's Avatar
vpopper vpopper is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Jun 2000
Location: Southern California
Posts: 73 vpopper User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 2 m 24 sec
Reputation Power: 9
<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...



Reply With Quote
Reply

Viewing: Dev Shed ForumsProgramming LanguagesPerl Programming > Using $: to change break line character


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump


Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 





© 2003-2008 by Developer Shed. All rights reserved. DS Cluster 1 hosted by Hostway