On Thu, Dec 26, 2013 at 5:34 PM, John W. Krahn jwkr...@shaw.ca wrote:
Kenneth Wolcott wrote:
Hello;
Hello Kenneth,
I'm trying to obtain line-by-line output from a command pipe in perl.
Unfortunately, I am firmly held to 5.8.8 version of perl on this
specific machine
Hello;
I'm trying to obtain line-by-line output from a command pipe in perl.
Unfortunately, I am firmly held to 5.8.8 version of perl on this
specific machine :-(
Apparently, creating an array for my command prevents me from
including the final pipe symbol when trying to use the three
On Mon, 23 Dec 2013 15:02:13 -0800
Kenneth Wolcott kennethwolc...@gmail.com wrote:
open my $fh, @cmd, | or die blah: $!\n; fails, Unknown open()
mode '5'
If you use an array, it is _not_ sent thru the shell. Try the
three-argument open:
open my $fh, '-|', @cmd or die blah: $!\n; fails,
Hi all,
On Mon, 23 Dec 2013 18:48:24 -0500
Shawn H Corey shawnhco...@gmail.com wrote:
On Mon, 23 Dec 2013 15:02:13 -0800
Kenneth Wolcott kennethwolc...@gmail.com wrote:
open my $fh, @cmd, | or die blah: $!\n; fails, Unknown open()
mode '5'
If you use an array, it is _not_ sent thru
Want to do a perl program -
Read from file 1 - line1, line2etc
Search line1 on file2 (all lines)
Then Search line 2 on file 2...
Ouput results of search.
--
To unsubscribe, e-mail: beginners-unsubscr...@perl.org
For additional commands, e-mail: beginners-h...@perl.org
http
manu wrote:
Want to do a perl program -
Read from file 1 - line1, line2etc
Search line1 on file2 (all lines)
Then Search line 2 on file 2...
Ouput results of search.
What code do you have so far?
--
Just my 0.0002 million dollars worth,
Shawn
Programming is as much
manu wrote:
Want to do a perl program -
Read from file 1 - line1, line2etc
Search line1 on file2 (all lines)
Then Search line 2 on file 2...
Ouput results of search.
perldoc -q How can I read in an entire file all at once
perldoc -q How do I efficiently match many regular expressions
Hi,
Need some help
How can I parse a file line by line using perl.
I want to parse a test file having following data format
*File : user_stats.txt*
20GB Larry
14.5MB Bob
3MBJohn
so that I can send this data to a MySQL database table.
Can I use while loop (any other loop control
On Tue Mar 10 2009 @ 4:13, Meghanand Acharekar wrote:
Hi,
Need some help
How can I parse a file line by line using perl.
I want to parse a test file having following data format
*File : user_stats.txt*
20GB Larry
14.5MB Bob
3MBJohn
so that I can send this data
On Oct 28, 2:51 pm, [EMAIL PROTECTED] (Andy Cravens) wrote:
-Original Message-
From: slow_leaner [mailto:[EMAIL PROTECTED]
Sent: Tue 10/28/2008 11:58 AM
To: [EMAIL PROTECTED]
Subject: matching elements from array and print the results line by line from
log file
Hi,
I have a list
slow_leaner wrote:
On Oct 28, 2:51 pm, [EMAIL PROTECTED] (Andy Cravens) wrote:
-Original Message-
From: slow_leaner [mailto:[EMAIL PROTECTED]
Sent: Tue 10/28/2008 11:58 AM
To: [EMAIL PROTECTED]
Subject: matching elements from array and print the results line by line from
log file
Hi
) || die can't open cisco.log
file!;
@cisco.log = FILE;
close (FILE);
@array = qw( BPDUGUARD FAN_FAIL ); # more then 2 elements in array
while (@cisco.log){
foreach $line (@array){
$_ =~ $line; #DOESN'T WORK AND I AM STUCK..
print $_\n; #WANT TO PRINT THAT MATCH
-Original Message-
From: slow_leaner [mailto:[EMAIL PROTECTED]
Sent: Tue 10/28/2008 11:58 AM
To: beginners@perl.org
Subject: matching elements from array and print the results line by line from
log file
Hi,
I have a list of element in array that I would like to match the
pattern
lines from a file. Remove:
@cisco.log = FILE;
close (FILE);
from above and then your while loop should be:
while ( FILE ) {
foreach $line (@array){
$_ =~ $line; #DOESN'T WORK AND I AM STUCK..
You are performing the match in void context so it is superfluous. See
the FAQ entry
Hi all
Thanks for all the help with this, going to have some fun implementing it :)
Thanks
Pat
--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
http://learn.perl.org/
On Jun 20, 1:30 pm, [EMAIL PROTECTED] (John W. Krahn) wrote:
Here is another way to do it:
my $jump;
while ( FILE ) {
$jump = $. + 10 if /regex/;
print the output if $jump == $.;
}
Two observations:
1. this will warn while $jump is undef
2. if regex is matched by one of the
Hi all
I am looking at a way of reading a line doing a regex to find the
specific line then pick out the line, sudo code would be some thing
like the following:
read in line
check regex
if regex is correct
{jump 10 lines
print the output
}
any ideas on jumping the 10 lines, how do I
On Fri, Jun 20, 2008 at 09:06, Pat Rice [EMAIL PROTECTED] wrote:
Hi all
I am looking at a way of reading a line doing a regex to find the
specific line then pick out the line, sudo code would be some thing
like the following:
read in line
check regex
if regex is correct
{jump 10
On Fri, Jun 20, 2008 at 8:06 AM, Pat Rice [EMAIL PROTECTED] wrote:
Hi all
I am looking at a way of reading a line doing a regex to find the
specific line then pick out the line, sudo code would be some thing
like the following:
read in line
check regex
if regex is correct
{jump 10
Pat Rice wrote:
Hi all
Hello,
I am looking at a way of reading a line doing a regex to find the
specific line then pick out the line, sudo code would be some thing
like the following:
read in line
check regex
if regex is correct
{jump 10 lines
print the output
}
any ideas
I am looking at a way of reading a line doing a regex to find the
specific line then pick out the line, sudo code would be some thing
like the following:
read in line
check regex
if regex is correct
{jump 10 lines
print the output
}
any ideas on jumping the 10 lines, how do I
Hi,
I have a program that contains a pretty big block of text:
my $text = EOF;
line1
line2
...
line 12
EOF
I want to read this block of text line by line and analyse each line without
needing to create a big array that contains all these lines (exactly like
when reading line by line from
Octavian Rasnita wrote:
Hi,
I have a program that contains a pretty big block of text:
my $text = EOF;
line1
line2
...
line 12
EOF
I want to read this block of text line by line and analyse each line without
needing to create a big array that contains all these lines (exactly
of Perl unless $] = 5.008;
my $text = EOF;
line1
line2
...
line 12
EOF
open my $fh, '', \$text or die $!;
while ($fh) {
print;
}
OUTPUT
line1
line2
...
line 12
Wow. Learn something new every day. That's a really nifty trick.
It requires you to put a lengthy heredoc in the middle
From: Rob Dixon [EMAIL PROTECTED]
I have a program that contains a pretty big block of text:
my $text = EOF;
line1
line2
...
line 12
EOF
I want to read this block of text line by line and analyse each line
without
needing to create a big array that contains
On 08/09/2006 11:15 AM, Octavian Rasnita wrote:
Hi,
I have a program that contains a pretty big block of text:
my $text = EOF;
line1
line2
...
line 12
EOF
I want to read this block of text line by line and analyse each line without
needing to create a big array that contains all
Octavian Rasnita wrote:
Hi,
Hello,
I have a program that contains a pretty big block of text:
my $text = EOF;
line1
line2
...
line 12
EOF
I want to read this block of text line by line and analyse each line without
needing to create a big array that contains all these lines
Octavian Rasnita wrote:
Thank you very much for your suggestion. It works, but unfortunately very
very slow.
If I put the data after __DATA__ and read DATA, it works very fast, but if
I create a $text var that holds the same data then open(DATA, , \$text),
it works more than 100 times
. Is there a way i can just load a single
line one at a time??
Also if the file(text contents) is a compressed file, which can be viewed
with 'less' and catted by 'zcat' and uncompressed
by 'uncompress' in linux, what's the best way to uncompress it on the fly???
At the moment i am uncompressing all of them
of parsing gets done. Is there a way i can just load a single
line one at a time??
Also if the file(text contents) is a compressed file, which can be viewed
with 'less' and catted by 'zcat' and uncompressed
by 'uncompress' in linux, what's the best way to uncompress it on the fly???
At the moment i am
and then the
following job of parsing gets done. Is there a way i can just load
a single
line one at a time??
Can you send the part that is actually _reading_ from FILE? Are the
contents of 'file' compressed?
Also if the file(text contents) is a compressed file, which can be
viewed
with 'less
and then the following job of parsing gets done. Is there a way i can just
load a single line one at a time??
Yes there is:
open FILE, 'file' or die Couldn't open 'file' $!;
while ( my $line = FILE ) {
...
}
Also if the file(text contents) is a compressed file, which can be viewed
with 'less' and catted
Hi all
thanks for the reply.
The gzip and zcat ones seem like what i was looking for.
But about the reading part:
I was using the same way for reading. I thought that was the standard way.
But the thing is even though i am readin the file line by line, the file is
loaded
completely
line by line, the
file is
loaded
completely to the memory while i am opening it with the handle.
^^^
Maybe you mean when you start _reading_? Does the while loop once and
in that single iteration $record holds the entire file? If that is
the case
Hello all,
Is there a way you read input from a script line by line. I'd rather
parse output line by line than do: @out = `script.sh`; which seems
sloppy. Or is that the best way?
TIA
This way works
open(my $FH, 'script.sh |') or die ...;
while (my $line = $FH) {
...
}
close($FH);
On 6/9/05, Tielman Koekemoer (TNE) [EMAIL PROTECTED] wrote:
Hello all,
Is there a way you read input from a script line by line. I'd rather
parse output line by line than do: @out
Thanks Marcos.
-Original Message-
From: marcos rebelo [mailto:[EMAIL PROTECTED]
Sent: 09 June 2005 09:48 AM
To: Tielman Koekemoer (TNE)
Cc: Perl Beginners
Subject: Re: Read output from script line by line
This way works
open(my $FH, 'script.sh |') or die ...;
while (my
Thanks Thomas.
-Original Message-
From: Thomas Bätzler [mailto:[EMAIL PROTECTED]
Sent: 09 June 2005 09:50 AM
To: 'Perl Beginners'
Cc: Tielman Koekemoer (TNE)
Subject: RE: Read output from script line by line
Tielman Koekemoer (TNE) [EMAIL PROTECTED] asked:
Is there a way you
I'm trying to match a patern in a string but I want to do it a line at a
time. Is there an easier way than this :
while ($a =~ m/(.+?)\n/g ) {
if ($1 =~ /whatever/g) {
print $1;
}
--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
http
why not to split the String first
something like
foreach my $line (split(/\n/, $a)) {
if ($line =~ /whatever/) {
print $line;
}
}
shall do the trick
Marcos
-Original Message-
From: bzzt [mailto:[EMAIL PROTECTED]
Sent: Wednesday, June 16, 2004 1:33 PM
To: [EMAIL
On Jun 16, bzzt said:
I'm trying to match a patern in a string but I want to do it a line at a
time. Is there an easier way than this :
while ($a =~ m/(.+?)\n/g ) {
if ($1 =~ /whatever/g) {
print $1;
}
Your regex, /(.+?)\n/, is unnecessarily complex. The ? modifier on .+
isn't
Hi, I have a file extremely large in size and length. I want to read the
file line by line and worry about matching up each line and running that
line through a subroutine instead of opening the entire file (which would
take a while).
So how do I open a file up and process each line individually
On Dec 17, 2003, at 7:28 PM, PerlDiscuss - Perl Newsgroups and mailing
lists wrote:
Hi, I have a file extremely large in size and length. I want to read
the
file line by line and worry about matching up each line and running
that
line through a subroutine instead of opening the entire file
Dan Muey wrote:
Howdt list.
I've never had to work with really big files before( I'm used to tiny
ones you can slurp in at once) and now I have to process a 180MB text
file line by line and was wondering the most efficient method to do
so form within a script not via coommand line
Howdt list.
I've never had to work with really big files before( I'm used to tiny ones you can
slurp in at once) and now I have to process a 180MB text file line by line and was
wondering the most efficient method to do so form within a script not via coommand
line.
Would I just do
open(FH
The difference is that Perl reads the entire file into memory when you do a
@file = FILE, but it only reads one line at a time if you do a
while(FILE). The difference definitely becomes clear if you try to do
that with a 180MB file on a machine with 128MB RAM.
-Original Message-
From
the amount of the file size is now needed in RAM.
foreach (@file) {
print $_;
}
and with a While?
With a while loop, the program reads line by line,
thus only about the line length size is allocated by the program in RAM.
Greetings,
Janek
--
To unsubscribe, e-mail: [EMAIL
Hi!
Reading all these message about reading a 'big' file (I know that 180MB its
not a big file), but what's the difference from reading like this:
@file = FILE;
foreach (@file) {
print $_;
}
and with a While?
Thanks!!
--
Pablo Fischer Sandoval ([EMAIL PROTECTED])
Howdt list.
I've never had to work with really big files before( I'm used
to tiny ones you can slurp in at once) and now I have to
process a 180MB text file line by line and was wondering the
most efficient method to do so form within a script not via
coommand line.
Would I
Dan Muey wrote:
Howdt list.
I've never had to work with really big files before( I'm
used to tiny
ones you can slurp in at once) and now I have to process a
180MB text
file line by line and was wondering the most efficient method to do
so form within a script not via coommand
-Original Message-
From: Dan Muey [mailto:[EMAIL PROTECTED]
Sent: Tuesday, August 05, 2003 12:27 PM
To: [EMAIL PROTECTED]
Subject: Large file line by line
Howdt list.
I've never had to work with really big files before( I'm used
to tiny ones you can slurp in at once
Pablo Fischer wrote:
Hi!
Reading all these message about reading a 'big' file (I know that
180MB its not a big file), but what's the difference from reading
like this:
@file = FILE;
foreach (@file) {
print $_;
}
Attemping to read in the whole file into memory while with
On a Unix system you could use 'lc' to count the lines and 'top' or 'tail'
to read the first or last lines. My Unix is getting rusty, but there are
functions to do what you want - so you could do something like:
my $linecount = `cat file.txt| lc`;
to get the line count. I'm sure that the lc
you probably don't have
'wc' on a DOS system either. You'll probably find that your routine is as
good as it gets anyway.
Gary
to get the line count. I'm sure that the lc command needs something else,
so you will have to play with it to get it to work. I used to use
something like
t=`wc -l file.txt`;
you'll give your machine less work to do. Also, I don't know how well DOS
systems handle pipes and multiple processes. In fact you probably don't
have
'wc' on a DOS system either. You'll probably find that your routine is as
good as it gets anyway.
Gary
to get
Madhu Reddy wrote:
Hi,
How to get first line, last line and no of lines in
a file.
is there any perl functions available for that ?
right now what i am doing is
open file
while (FH
{
$lines++;
}
close(FH)
This operation is expensive..
suppose, if file have millions
Subject: How to get 1st line, last line and no of lines in a file
is there any perl functions available for that ?
suppose, if file have millions of records,
ok
If it's a small file, try Tie::File by (I believe) Mark Jason Dominus.
It's very cool.
For a big file, I'm not sure there's
Hi,
How to get first line, last line and no of lines in
a file.
is there any perl functions available for that ?
right now what i am doing is
open file
while (FH
{
$lines++;
}
close(FH)
This operation is expensive..
suppose, if file have millions of records,
it will take more time
-Original Message-
From: Madhu Reddy [mailto:[EMAIL PROTECTED]]
Sent: Wednesday, February 19, 2003 1:25 PM
To: [EMAIL PROTECTED]
Subject: How to get 1st line, last line and no of lines in a file
Hi,
How to get first line, last line and no of lines in
a file
declaration in same scope at
./nudice-strict_test line 114.
Line 114 (which now points to the right line, thank you so much!!) only
shifts an element off of @rawRollArray, which has been declared as a
my variable earlier on:
my @rawRollArray = roll(@currentRollRequest); # produces raw roll array
from
variable @rawRollArray masks earlier declaration in same scope at
./nudice-strict_test line 114.
Line 114 (which now points to the right line, thank you so much!!) only
shifts an element off of @rawRollArray, which has been declared as a
my variable earlier on:
my @rawRollArray = roll
John W. Krahn [EMAIL PROTECTED] wrote in message
[EMAIL PROTECTED]">news:[EMAIL PROTECTED]...
my @rawRollArray = roll(@currentRollRequest); # produces raw roll
array
from roll request array
while @rawRollArray {
^^^
You are missing the parenthesis around the while
errors I could not
decipher. Adding back use strict and troubleshooting away some other
errors, I get as error #1:
my variable @rawRollArray masks earlier declaration in same scope at
./nudice-strict_test line 114.
Line 114 (which now points to the right line, thank you so much!!) only
shifts
Christopher D. Lewis wrote:
snip
Can you direct me to a resource which will help me to see what
needs to happen here?
snip
Start here:
http://perl.plover.com/FAQs/Namespaces.html
perldoc -f my
perldoc -f our
as the others have mentioned 'strict' is your friend (to put it lightly).
Is there a more efficient way of approaching this?
I open 1 file for reading and another for writing. The script examines each
line of the file being read and if any of the following words or digits
matches, skip the line and go to the next. Write everything else to another
file.
while
a file line-by-line
Is there a more efficient way of approaching this?
I open 1 file for reading and another for writing. The script
examines each
line of the file being read and if any of the following words
or digits
matches, skip the line and go to the next. Write everything
On Apr 15, Dave Chappell said:
I open 1 file for reading and another for writing. The script examines each
line of the file being read and if any of the following words or digits
matches, skip the line and go to the next. Write everything else to another
file.
while (IN) {
next if /(\d5
There's a simpler way, if you specify the file from the command line (as in
script.pl file) you can do
while () {
last if /search test/;
#do something
}
in fact, you can make a cat-like script like this:
while () {
print;
}
is the diamond operator, and it's the filehandle
Greetings, I am trying to read a text file into a scalar variable line by line
until EOF or a search test if fullfilled. I have been reading files in like
this:
chomp (@line = `cat filename`);
I do not want to do this beacuse my file is quite large, and there is no reason
to hog the memory
On Wed, 27 Feb 2002, Jon Serra wrote:
Greetings, I am trying to read a text file into a scalar variable line by line
until EOF or a search test if fullfilled. I have been reading files in like
this:
chomp (@line = `cat filename`);
I do not want to do this beacuse my file is quite large
Here's something simple:
open(FILE, /export/home/me/filename);
while ($line = FILE)
{
# whatever
}
FILE is a filehandle, and by defualt it will give you back a line at a time.
You can also put the whole thing into an array by doing this:
@file = FILE;
At least, I think that's
Jon Serra wrote:
Greetings, I am trying to read a text file into a scalar variable line by line
until EOF or a search test if fullfilled. I have been reading files in like
this:
chomp (@line = `cat filename`);
I do not want to do this beacuse my file is quite large
At 07:11 AM 08/04/2001 -0700, Arthur Klassen wrote:
[EMAIL PROTECTED] wrote:
Michael Fowler [EMAIL PROTECTED] said:
You left out the Macintosh EOL sequence, LFCR, and I don't know
what uses simply CR as EOL.
Macs use just CR. No machine that I know of uses LFCR as a line
terminator
On Fri, Aug 03, 2001 at 01:40:30PM -0700, [EMAIL PROTECTED] wrote:
Michael Fowler [EMAIL PROTECTED] said:
You left out the Macintosh EOL sequence, LFCR, and I don't know what
uses simply CR as EOL.
Macs use just CR. No machine that I know of uses LFCR as a line
terminator.
Right
74 matches
Mail list logo