Beefy Boxes and Bandwidth Generously Provided by pair Networks
We don't bite newbies here... much
 
PerlMonks  

Extracting Multiline Records from a file

by DeliriumNZ (Novice)
on Jun 25, 2009 at 14:13 UTC ( [id://774728]=perlquestion: print w/replies, xml ) Need Help??

DeliriumNZ has asked for the wisdom of the Perl Monks concerning the following question:

Hi guys I need some help. Im creating a program that opens a log file with multiline records in it. I am wanting to split these records up and count how many records there are. I have created a program originally which finds particular records for a particular phone number. The code for that is:
while(<LOGFILE>) { if(/^.*$PhoneNumber$/../^________________________________$/) { }
Basically these records have the data start off with 000001 xxxxxx (xxxxxx being the telephone number) and the record ends with ______________________. The one I want to create has a record that starts off with 000001 Call ID 000001. But using the same code it doesn't work. Is there something different I need to do in the if statement?

Replies are listed 'Best First'.
Re: Extracting Multiline Records from a file
by davorg (Chancellor) on Jun 25, 2009 at 14:55 UTC

    Isn't that exactly what $/ is for?

    { local $/ = "________________________________\n"; while (<LOGFILE>) { # do stuff with a single record } }
    --

    See the Copyright notice on my home node.

    Perl training courses

Re: Extracting Multiline Records from a file
by Transient (Hermit) on Jun 25, 2009 at 14:28 UTC
    Not knowing the particular line you're trying to use, try enclosing the $PhoneNumber with \Q and \E a la:
    /^.*\Q$PhoneNumber\E$ / ...
    The \Q and \E tell the perl regex interpreter to ignore special characters that may exist in your $PhoneNumber variable (such as parens and dashes)
Re: Extracting Multiline Records from a file
by moritz (Cardinal) on Jun 25, 2009 at 14:43 UTC
    You tell us that something doesn't work. We don't know the input data, the regex (ie we don't know what exactly is in $PhoneNumber, and we don't know in what way it doesn't work.

    How do you expect us to help you?

    Pleas read How (Not) To Ask A Question, and provide more information and sample data (anonymized/randomized if you don't want to exhibit any private data).

Re: Extracting Multiline Records from a file
by si_lence (Deacon) on Jun 25, 2009 at 14:54 UTC
    Or maybe - just guessing as the others - you assignment to your $PhoneNumber is not doing what you expect

    my $PhoneNumber = 000001; print "[$PhoneNumber] \n"; output: [1]
    cheers

    si_lence

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: perlquestion [id://774728]
Approved by Corion
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others about the Monastery: (6)
As of 2024-04-16 10:56 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found