Ask a Question related to PERL Beginners, Design and Development.
-
Jose Malacara #1
formats
Is it possible to use more than one format in a script? I am parsing a log file to STDOUT and would like to be able to write to two (or more) different formats depending on the information found in the log.
This is what I'm trying to do:
1. open and read logfile
2. if you find "some_string" print to STDOUT using TYPE_1 format
3. if you find "other_string" print to STDOUT using TYPE_2 format
5. continue parsing logfile, etc
I can open and parse the logfile, my script breaks whenever I try to call more than one type of format. This doesn't seem to work for me, is this even possible?
format TYPE_1 =
Type: @<<<<<<<<<< Gateway: @<<<<<<<<< Acct ID: @<<<<<<<<<<<<<<<<<<
$record_type,$gateway,$acct_id
Start Date: @<<<<<<<<<< Start Time: @<<<<<<<<<
$start_date,$start_time
..
write TYPE_1;
format TYPE_2 =
Type: @<<<<<<<<<< Gateway: @<<<<<<<<< Acct ID: @<<<<<<<<<<<<<<<<<<
$record_type,$gateway,$acct_id
Start Date: @<<<<<<<<<< Start Time: @<<<<<<<<<
$start_date,$start_time
Disconnect Date: @<<<<<<<<<< Disconnect Time: @<<<<<<<<<
$disco_date,$disco_time
..
write TYPE_2;
Also, how would I go about keeping the filehandles open as it would be repetively "writing" each format.
Thank you,
Jose
Jose Malacara Guest
-
Play various formats
I want to make an application in which user can play any video files from its own. Either file is in .wmv format or .mpeg4, Flash playes it. Is it... -
save as formats
I have tried to save a scanned pdf to word using the save as feature. The entire three page typed document is treated as one image. I am using Adobbe... -
PNG Formats in Vista
Try this, see if this works. On Windows XP (with Classic theme): 1) Type in at Run, "winver" then press OK. 2) Press Alt+Printscreen when About... -
file formats?
hi, i am new to photoshop 7, so please bear with me, i have downloaded certain pictures off the net and i am trying to resize and then print them,... -
Tom Kinzer #2
RE: formats
To just use it for STDOUT, it's pretty straight forward, switching the
special $~ variable as needed.
You're switching FORMATs not filehandles. There may be a shortcut but this
is how I would do it for this problem:
-Tom Kinzer
_____________________
format TYPE_1 =
Im formated with type1: @<<<<<<<<< @||||||||||||||||||||||||||||||||||||||
$field1, $field2
..
format TYPE_2 =
IM FORMATTED WITH TYPE2: @<<<<<<<< @<<<<<<<<<<<<<<<<<<<<<<<<
$field1, $field2
..
open RECORDS, "< YourInput.log" or die;
while (<RECORDS>) {
($field1, $field2) = split;
if ( m/YourPatternRegExHere/ ) {
$~ = 'TYPE_1';
} else {
$~ = 'TYPE_2';
}
write;
}
close RECORDS;
__END__
-----Original Message-----
From: Jose Malacara [mailto:josem@thrifty.net]
Sent: Friday, December 05, 2003 6:40 PM
To: [email]beginners@perl.org[/email]
Subject: formats
Is it possible to use more than one format in a script? I am parsing a log
file to STDOUT and would like to be able to write to two (or more) different
formats depending on the information found in the log.
This is what I'm trying to do:
1. open and read logfile
2. if you find "some_string" print to STDOUT using TYPE_1 format
3. if you find "other_string" print to STDOUT using TYPE_2 format
5. continue parsing logfile, etc
I can open and parse the logfile, my script breaks whenever I try to call
more than one type of format. This doesn't seem to work for me, is this even
possible?
format TYPE_1 =
Type: @<<<<<<<<<< Gateway: @<<<<<<<<< Acct ID: @<<<<<<<<<<<<<<<<<<
$record_type,$gateway,$acct_id
Start Date: @<<<<<<<<<< Start Time: @<<<<<<<<<
$start_date,$start_time
..
write TYPE_1;
format TYPE_2 =
Type: @<<<<<<<<<< Gateway: @<<<<<<<<< Acct ID: @<<<<<<<<<<<<<<<<<<
$record_type,$gateway,$acct_id
Start Date: @<<<<<<<<<< Start Time: @<<<<<<<<<
$start_date,$start_time
Disconnect Date: @<<<<<<<<<< Disconnect Time: @<<<<<<<<<
$disco_date,$disco_time
..
write TYPE_2;
Also, how would I go about keeping the filehandles open as it would be
repetively "writing" each format.
Thank you,
Jose
Tom Kinzer Guest
-
Drieux #3
Re: formats
On Dec 5, 2003, at 6:39 PM, Jose Malacara wrote:
[..]that's the sticky bit, where tom is> write TYPE_1;
talking about not writing to a filehandle...
[..]
To expand on tom's comments a bit:
<http://www.wetware.com/drieux/pbl/perlTrick/Format/funk_the_form.plx>
which generates
Type: type1 Gateway: cow Acct ID: lost_id
Start Date: 2003.12.2 Start Time: 1400
#---------------
Type: type2 Gateway: pig Acct ID: new
Start Date: 2003.12.2 Start Time: 1400
Disconnect Date: 2003.12.3 Disconnect Time: 1600
one needs to be thinking in terms of
$~ = 'TYPE_1';
write;
$~ = '';
print "#---------------\n";
HTH.
ciao
drieux
---
Drieux Guest



Reply With Quote

