Re: Looping regexes against a list

2015-01-20 Thread Charles DeRykus
On Tue, Jan 20, 2015 at 9:47 AM, Mike Martin wrote: > Thanks for the idea about qr, I did try this before, but I've now relooked > at at it and got about 75% improvement. > > As regards the uninitialized point the errors were coming from regexes > (different ones) when the regex wasnt matching, so

Re: Looping regexes against a list

2015-01-20 Thread Shawn H Corey
On Tue, 20 Jan 2015 17:47:58 + Mike Martin wrote: > Take a load of Job Vacancy posts (xml files - loads of) > Parse the Information, getting rid of as much garbage as possible > Push a distinct list into a lookup hash If you're running Linux (or any POSIX), see `man sort` and search for /-u/

Re: Looping regexes against a list

2015-01-20 Thread Mike Martin
Thanks for the idea about qr, I did try this before, but I've now relooked at at it and got about 75% improvement. As regards the uninitialized point the errors were coming from regexes (different ones) when the regex wasnt matching, so testing the result of each regex match was not really an opti

Re: Looping regexes against a list

2015-01-20 Thread Shawn H Corey
What the OP should do is put the regexes in a Perl module and unroll the loop. That way, he can group them so that groups of tests are skipped: # strings containing "foo" if( /foo/ ){ return "food" if /food/; return "fool" if /fool/; return "foot" if /foot/; return "foo"; } --

Re: Looping regexes against a list

2015-01-20 Thread Shawn H Corey
On Tue, 20 Jan 2015 10:23:42 -0500 Brandon McCaig wrote: > On Tue, Jan 20, 2015 at 10:21 AM, Brandon McCaig > wrote: > > perldoc -f qr// > > I was sure that worked in my up-to-date perlbrew environments, but it > isn't working in Cygwin running perl 5.14.2 so in the event that it > doesn't work

Re: Looping regexes against a list

2015-01-20 Thread Brandon McCaig
On Tue, Jan 20, 2015 at 10:21 AM, Brandon McCaig wrote: > perldoc -f qr// I was sure that worked in my up-to-date perlbrew environments, but it isn't working in Cygwin running perl 5.14.2 so in the event that it doesn't work for you look at `perldoc -f qr' and `perldoc perlop' (then search for "q

Re: Looping regexes against a list

2015-01-20 Thread Brandon McCaig
On Tue, Jan 20, 2015 at 9:51 AM, Andrew Solomon wrote: > Aside from this lengthy rant^H^H^H^H discussion:) about where you put > your regex, have you made any progress on the performance problem you > put forward at the outset? I'm not quite sure that I understand what the OP is doing still, but

Re: Looping regexes against a list

2015-01-20 Thread Andrew Solomon
Hey Mike Aside from this lengthy rant^H^H^H^H discussion:) about where you put your regex, have you made any progress on the performance problem you put forward at the outset? cheers Andrew On Tue, Jan 20, 2015 at 6:41 AM, Danny Spell wrote: > For me, regex can be simple or complex. > It depen

Re: Looping regexes against a list

2015-01-19 Thread Danny Spell
For me, regex can be simple or complex. It depends on the task at hand. The more complex the task, the more complex the regex. My boss who can code, but doesn't want to, *HATES* regex. Personally, I think it is pretty powerful and I'm grateful for its flexibility. I use it daily in my job where s

Re: Looping regexes against a list

2015-01-19 Thread Shawn H Corey
On Mon, 19 Jan 2015 11:43:41 -0500 John Mason wrote: > On Mon, Jan 19, 2015 at 11:36 AM, Shawn H Corey > wrote: > > > On Mon, 19 Jan 2015 11:18:01 -0500 > > bill pemberton wrote: > > > > > I fail to see why a regex can only be changed by a programmer. > > > please expand upon this. > > > > You

Re: Looping regexes against a list

2015-01-19 Thread John Mason
On Mon, Jan 19, 2015 at 11:36 AM, Shawn H Corey wrote: > On Mon, 19 Jan 2015 11:18:01 -0500 > bill pemberton wrote: > > > I fail to see why a regex can only be changed by a programmer. please > > expand upon this. > > You shouldn't blindly trust input from a user, there should be checking/limit

Re: Looping regexes against a list

2015-01-19 Thread Shawn H Corey
On Mon, 19 Jan 2015 11:18:01 -0500 bill pemberton wrote: > I fail to see why a regex can only be changed by a programmer. please > expand upon this. Regex is a programming language in its own right. Why should an average user have any knowledge of it? -- Don't stop where the ink does.

Re: Looping regexes against a list

2015-01-19 Thread Shawn H Corey
On Mon, 19 Jan 2015 15:57:35 + Andrew Solomon wrote: > On Mon, Jan 19, 2015 at 2:50 PM, Mike Martin > wrote: > > The lookup hash is like this > > %clean=( > > HeatingEngineer => (?:Heating.*?Engineer)\b.*? > > HGV > > Driver=>(?=\A(?:(?!tech|mech).)*$)(?:HGV|LGV|Class.?1|Class.?2).?(?

Re: Looping regexes against a list

2015-01-19 Thread Andrew Solomon
First question which comes to mind is - do you really need to call sort in those two foreach collections? Sort can often take time, and the fact that you've got one sort nested inside a foreach loop is bad karma:) Andrew On Mon, Jan 19, 2015 at 2:50 PM, Mike Martin wrote: > The lookup hash is li

Re: Looping regexes against a list

2015-01-19 Thread Mike Martin
The lookup hash is like this %clean=( HeatingEngineer => (?:Heating.*?Engineer)\b.*? HGV Driver=>(?=\A(?:(?!tech|mech).)*$)(?:HGV|LGV|Class.?1|Class.?2).?(?:1|2|3|)(?:.+Driver|).*? HGV Mechanic=> (?:(?:HGV|LGV|Lorry).+(?:Mech?anics?|technicians?))\b.*? Highway Engineer=> (?:(?:Highway.?) (?:En

Re: Looping regexes against a list

2015-01-19 Thread Brandon McCaig
Mike: On Mon, Jan 19, 2015 at 01:25:56PM +, Mike Martin wrote: > Hi Hello, > I am looking for the most performant way to achieve this > > I have a big list of text (47+ lines in a hash) I then run > a hash ref consisting of replacement text - pattern to search - > optional 3rd param for

Looping regexes against a list

2015-01-19 Thread Mike Martin
Hi I am looking for the most performant way to achieve this I have a big list of text (47+ lines in a hash) I then run a hash ref consisting of replacement text - pattern to search - optional 3rd param for grouping matches So I loop through the text and then loop the regex hash against each r

Re: looping through an array with for

2012-02-15 Thread Igor Dovgiy
Hi Jim, Well, instead of asking at each step, whether the last element is processed or not, it's slightly better to exclude it from the loop: for my $i (0..$#keyFields - 1) { printf "%s %s", $keyFields[$i], $match; } printf "%s %s", $keyFields[-1], $lastmatch; But yes, I guess your last approa

Re: looping through an array with for

2012-02-15 Thread Chris Stinemetz
Thank you Jim. Your suggestions worked perfectly! -- To unsubscribe, e-mail: beginners-unsubscr...@perl.org For additional commands, e-mail: beginners-h...@perl.org http://learn.perl.org/

Re: looping through an array with for

2012-02-14 Thread Jim Gibson
At 9:08 PM -0700 2/14/12, Chris Stinemetz wrote: I have a for loop I would like to alter so that when the iteration reaches the last element in the array the varibale $lastmatch is passed to printf instead of $match. Does anyone have any suggestions? my $match = "GE 0 AND "; my $lastmatch = "GE

looping through an array with for

2012-02-14 Thread Chris Stinemetz
I have a for loop I would like to alter so that when the iteration reaches the last element in the array the varibale $lastmatch is passed to printf instead of $match. Does anyone have any suggestions? my $match = "GE 0 AND "; my $lastmatch = "GE 0"; for my $i (0 .. $#keyFields) { printf "%s %

Re: Looping in Test::Harness

2010-04-09 Thread Uri Guttman
> "BM" == Bob McConnell writes: BM> From: Uri Guttman >> >> you can even use perl itself. just write a perl data structure and >> call do on it. it can be an anon array or hash which is the >> returned value. no need to learn yaml or load another module. you >> can also slurp/ev

RE: Looping in Test::Harness

2010-04-09 Thread Bob McConnell
From: Uri Guttman > "BM" == Bob McConnell writes: > BM> From: Philip Potter > >> On 6 April 2010 16:52, Bob McConnell wrote: > >>> I have a test harness set up with a series of Selenium test scripts. > >>> Each script tests a specific scenario on my web site. But I have some > >>> scen

Re: Looping in Test::Harness

2010-04-09 Thread Uri Guttman
> "BM" == Bob McConnell writes: BM> From: Philip Potter >> On 6 April 2010 16:52, Bob McConnell wrote: >>> I have a test harness set up with a series of Selenium test scripts. >>> Each script tests a specific scenario on my web site. But I have some >>> scenarios that I want to tes

Re: Looping in Test::Harness

2010-04-09 Thread Philip Potter
On 9 April 2010 18:04, Bob McConnell wrote: > After a great deal of reading and speculation, it looks like YAML is the > way to go. I will have to move the loop inside each test script, and > iterate thorough the records read. The biggest problem is that the plan > is no longer fixed, so I do lose

RE: Looping in Test::Harness

2010-04-09 Thread Bob McConnell
From: Philip Potter > On 6 April 2010 16:52, Bob McConnell wrote: >> I have a test harness set up with a series of Selenium test scripts. >> Each script tests a specific scenario on my web site. But I have some >> scenarios that I want to test multiple times with different data entered >> each ti

Re: Looping in Test::Harness

2010-04-06 Thread Brandon McCaig
On Tue, Apr 6, 2010 at 11:52 AM, Bob McConnell wrote: > Is there a cleaner way to pass those variables into each test script? I'm unfamiliar with testing practices in Perl, but I would imagine that almost anything would be better than using environment variables to store test values (IMO, at leas

Re: Looping in Test::Harness

2010-04-06 Thread Philip Potter
On 6 April 2010 16:52, Bob McConnell wrote: > I have a test harness set up with a series of Selenium test scripts. > Each script tests a specific scenario on my web site. But I have some > scenarios that I want to test multiple times with different data entered > each time. Currently I am using en

Looping in Test::Harness

2010-04-06 Thread Bob McConnell
I have a test harness set up with a series of Selenium test scripts. Each script tests a specific scenario on my web site. But I have some scenarios that I want to test multiple times with different data entered each time. Currently I am using environment parameters to pass the test data into each

Re: looping through multiple arrays

2008-09-04 Thread Jenda Krynicky
From: Bobby <[EMAIL PROTECTED]> > Hi, > > I have a large pipe delimited text file that i want to loop through > and sort out a column of data within that file. Let's call this column > $sizes. I want to group these different sizes into categories. i.e. > > @sizeA = ("A","B","C"); > @sizeB = ("D",

Re: looping through multiple arrays

2008-09-04 Thread John W. Krahn
Raja Vadlamudi wrote: On Thu, Sep 4, 2008 at 12:36 PM, Raja Vadlamudi <[EMAIL PROTECTED]> wrote: On Thu, Sep 4, 2008 at 11:22 AM, Bobby <[EMAIL PROTECTED]> wrote: I have a large pipe delimited text file that i want to loop through and sort out a column of data within that file. Let's call thi

Re: looping through multiple arrays

2008-09-04 Thread Raja Vadlamudi
On Thu, Sep 4, 2008 at 12:36 PM, Raja Vadlamudi <[EMAIL PROTECTED]> wrote: > > > On Thu, Sep 4, 2008 at 11:22 AM, Bobby <[EMAIL PROTECTED]> wrote: > >> Hi, >> >> I have a large pipe delimited text file that i want to loop through and >> sort out a column of data within that file. Let's call this c

looping through multiple arrays

2008-09-04 Thread Bobby
Hi, I have a large pipe delimited text file that i want to loop through and sort out a column of data within that file. Let's call this column $sizes. I want to group these different sizes into categories. i.e. @sizeA = ("A","B","C"); @sizeB = ("D","E","F"); @sizeC = ("G","H","I"); This is what

Re: looping

2008-06-30 Thread Gunnar Hjalmarsson
Jeff Peng wrote: On Tue, Jul 1, 2008 at 11:04 AM, Akhil Srivastava <[EMAIL PROTECTED]> wrote: Still I am not able to make it work. The problem is to read a file loop from inside a top loop and exit the file loop when the top loop finishes. You maybe should post the code piece to the list,

Re: looping

2008-06-30 Thread Jeff Peng
On Tue, Jul 1, 2008 at 11:04 AM, Akhil Srivastava <[EMAIL PROTECTED]> wrote: > Still I am not able to make it work. The problem is to read a file loop from > inside a top loop and exit the file loop when the top loop finishes. You maybe should post the code piece to the list, we may have the c

Re: looping

2008-06-30 Thread Jeff Peng
On Mon, Jun 30, 2008 at 3:24 PM, dakin999 <[EMAIL PROTECTED]> wrote: > > While I am reading each row data that is fetched by select query from > oracle databae, I need to read some other values from a text file. > This is where I am having issues. Can some one help me in formalising > the write sy

looping

2008-06-30 Thread dakin999
Hi, I am writting a perl script which: 1. Calls oracle database and produce the desired results While I am reading each row data that is fetched by select query from oracle databae, I need to read some other values from a text file. This is where I am having issues. Can some one help me in forma

Re: looping over arrayref of hashes

2008-06-20 Thread Rob Dixon
Graeme McLaren wrote: > Hi all, I'm in need of a loop, can't seem to find what I'm looking for > online. I want to loop over this array ref inserting each hash value into > the DB at each iteration.I've got the following data structure which is > assigned to $aref: > > my $VAR1 = [ > { >

Re: looping over arrayref of hashes

2008-06-19 Thread Narthring
On Jun 18, 11:27 am, [EMAIL PROTECTED] (Graeme McLaren) wrote: > Hi all, I'm in need of a loop, can't seem to find what I'm looking for > online.  I want to loop over this array ref inserting each hash value into > the DB at each iteration.I've got the following data structure which is > assigne

Re: looping over arrayref of hashes

2008-06-18 Thread Amit Saxena
Hi On the basis of what you have mentioned, I have made a sample code. Let me know if my understanding is different from yours. The Perl Code is copied below :- # cat u.pl #!/usr/bin/perl ##!/u01/app/oracle/product/10.1.0/db_1/perl/bin/perl # # Hi all, I'm in need of a loop, can't seem to fin

Re: looping over arrayref of hashes

2008-06-18 Thread Gunnar Hjalmarsson
Graeme McLaren wrote: Hi all, I'm in need of a loop, can't seem to find what I'm looking for online. I want to loop over this array ref inserting each hash value into the DB at each iteration.I've got the following data structure which is assigned to $aref: $VAR1 = [ {

Re: looping over arrayref of hashes

2008-06-18 Thread Rodrick Brown
On Wed, Jun 18, 2008 at 12:27 PM, Graeme McLaren < [EMAIL PROTECTED]> wrote: > > Hi all, I'm in need of a loop, can't seem to find what I'm looking for > online. I want to loop over this array ref inserting each hash value into > the DB at each iteration.I've got the following data structure whic

looping over arrayref of hashes

2008-06-18 Thread Graeme McLaren
Hi all, I'm in need of a loop, can't seem to find what I'm looking for online. I want to loop over this array ref inserting each hash value into the DB at each iteration.I've got the following data structure which is assigned to $aref: $VAR1 = [ {'rate' => '1.98',

Re: looping 2 times through 5000 differs from 5000 times through 2

2008-06-12 Thread oldgeezer
Jenda Krynicky wrote: > From: Rob Dixon <[EMAIL PROTECTED]> > > oldgeezer wrote: > > > foreach my $entry (uniq @IK){ > > > foreach my $line(@DATA) { > > > # Note /;$entry;/ takes longer than > > > # /$entry;/ and that takes longer than /$entry/ > > > # But /$entry/ also splits remark

Re: looping 2 times through 5000 differs from 5000 times through 2

2008-06-12 Thread Jenda Krynicky
From: Rob Dixon <[EMAIL PROTECTED]> > oldgeezer wrote: > > foreach my $entry (uniq @IK){ > > foreach my $line(@DATA) { > > # Note /;$entry;/ takes longer than > > # /$entry;/ and that takes longer than /$entry/ > > # But /$entry/ also splits remarks_entries. > > # So I need the tr

Re: looping 2 times through 5000 differs from 5000 times through 2

2008-06-11 Thread Rob Dixon
oldgeezer wrote: > > Hi all, > > Sorry for the late response, I've been busy doing something else. That's cool. > As a newbie in this perl.beginners, I did not know that it is a good thing to > tell what purpose the script has. My script is purely hobby. All my scripts > are. As a general prin

Re: looping 2 times through 5000 differs from 5000 times through 2

2008-06-11 Thread Jenda Krynicky
From: oldgeezer <[EMAIL PROTECTED]> > But you also made me aware of a mistake > I always made until now. The three periods in > for (x...y) > I must have inherited that error from > another language. Probably from an > interpreter I wrote myself some 30 > years ago. It's not an error. Just so

Re: looping 2 times through 5000 differs from 5000 times through 2

2008-06-11 Thread oldgeezer
On Jun 8, 5:03 pm, [EMAIL PROTECTED] (Rob Dixon) wrote: > oldgeezer wrote: > > Hi all, > > > Last week I discovered this perl.beginners group. > > Good stuff here, albeit many times hard to grasp > > the answers. But I'm learning. > > > What I would l

Re: Looping through an anonymous array of arrays

2008-06-10 Thread Rob Dixon
Rodrick Brown wrote: > > my $arrayRef = [ 1, 2, 3, ['a', 'b', 'c', ["Hello"] ]]; > > I have no problem returning single elements but how would one walk this list > of elements with say a for loop? use strict; use warnings; my $arrayRef = [ 1, 2, 3, ['a', 'b', 'c', ["Hello"] ]]; my @flat = $arra

Re: Looping through an anonymous array of arrays

2008-06-08 Thread Randal L. Schwartz
> "(Randal" == (Randal L Schwartz) <[EMAIL PROTECTED]> writes: (Randal> my @items = @$arrayRef; (Randal> while (@items) { (Randal> if (ref $items[0]) { (Randal> if (ref $items[0] eq "ARRAY") { (Randal> unshift @items, @{shift @items}; # replace arrayref with co

Re: looping 2 times through 5000 differs from 5000 times through 2

2008-06-08 Thread Rob Dixon
oldgeezer wrote: > Hi all, > > Last week I discovered this perl.beginners group. > Good stuff here, albeit many times hard to grasp > the answers. But I'm learning. > > What I would like to understand is why looping > 2 times through 5000 lines takes less time than &

Re: Looping through an anonymous array of arrays

2008-06-08 Thread Randal L. Schwartz
> "Aruna" == Aruna Goke <[EMAIL PROTECTED]> writes: Aruna> for my $item (@$arrayRef){ Aruna> print $item unless ref($item) eq 'ARRAY'; Aruna> if(ref($item) eq 'ARRAY'){ Aruna>for my $item1(@$item){ Aruna>print $item1 unless ref($item1) eq 'ARRAY'; Aruna> { Arun

Re: looping 2 times through 5000 differs from 5000 times through 2

2008-06-08 Thread Jenda Krynicky
From: oldgeezer <[EMAIL PROTECTED]> > What I would like to understand is why looping > 2 times through 5000 lines takes less time than > looping 5000 times through 2 lines. > > To show what I mean, I wrote a snippet that > does nothing with the data and yet the first >

Re: looping 2 times through 5000 differs from 5000 times through 2

2008-06-08 Thread John W. Krahn
oldgeezer wrote: Hi all, Hello, Last week I discovered this perl.beginners group. Good stuff here, albeit many times hard to grasp the answers. But I'm learning. If you have any questions just ask (the list.) What I would like to understand is why looping 2 times through 5000

Re: Looping through an anonymous array of arrays

2008-06-08 Thread Dr.Ruud
"Rodrick Brown" schreef: > my $arrayRef = [ 1, 2, 3, ['a', 'b', 'c', ["Hello"] ]]; > > I have no problem returning single elements but how would one walk > this list of elements with say a for loop? Start writing it differently, maybe like: my $data = [ 1, 2, 3, [ 'a',

looping 2 times through 5000 differs from 5000 times through 2

2008-06-08 Thread oldgeezer
Hi all, Last week I discovered this perl.beginners group. Good stuff here, albeit many times hard to grasp the answers. But I'm learning. What I would like to understand is why looping 2 times through 5000 lines takes less time than looping 5000 times through 2 lines. To show what I me

Re: Looping through an anonymous array of arrays

2008-06-07 Thread Aruna Goke
Gunnar Hjalmarsson wrote: Rodrick Brown wrote: my $arrayRef = [ 1, 2, 3, ['a', 'b', 'c', ["Hello"] ]]; I have no problem returning single elements but how would one walk this list of elements with say a for loop? One way: my $level = 0; breakdown( $arrayRef ); sub breakdown {

Re: Looping through an anonymous array of arrays

2008-06-06 Thread Gunnar Hjalmarsson
Rodrick Brown wrote: my $arrayRef = [ 1, 2, 3, ['a', 'b', 'c', ["Hello"] ]]; I have no problem returning single elements but how would one walk this list of elements with say a for loop? One way: my $level = 0; breakdown( $arrayRef ); sub breakdown { my $ref = shift;

Re: Looping through an anonymous array of arrays

2008-06-06 Thread Chas. Owens
On Fri, Jun 6, 2008 at 9:31 PM, Rodrick Brown <[EMAIL PROTECTED]> wrote: > my $arrayRef = [ 1, 2, 3, ['a', 'b', 'c', ["Hello"] ]]; > > I have no problem returning single elements but how would one walk this list > of elements with say a for loop? > You can treat an array reference like an array by

Re: Looping through an anonymous array of arrays

2008-06-06 Thread Jeff Peng
On Sat, Jun 7, 2008 at 9:31 AM, Rodrick Brown <[EMAIL PROTECTED]> wrote: > my $arrayRef = [ 1, 2, 3, ['a', 'b', 'c', ["Hello"] ]]; > > I have no problem returning single elements but how would one walk this list > of elements with say a for loop? > Try this code: use strict; my $arrayRef = [ 1,

Looping through an anonymous array of arrays

2008-06-06 Thread Rodrick Brown
my $arrayRef = [ 1, 2, 3, ['a', 'b', 'c', ["Hello"] ]]; I have no problem returning single elements but how would one walk this list of elements with say a for loop?

Re: looping thru delete check boxes

2008-02-26 Thread Gunnar Hjalmarsson
ken uhl wrote: I have a page that displays a list of entries with Delete Check boxes how Do I loop thru all the checked entries, re-display in a 'confirmation' page and then do the deletes? Learn some about CGI. http://www.cgi.resourceindex.com/Documentation/CGI_Tutorials/ -- Gunnar Hjalmars

looping thru delete check boxes

2008-02-26 Thread ken uhl
I have a page that displays a list of entries with Delete Check boxes how Do I loop thru all the checked entries, re-display in a 'confirmation' page and then do the deletes? -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/

Re: Return number of keys in a hash of hash? Looping through "sub hash"?

2008-01-24 Thread pzimmermann
On Jan 24, 10:12 am, [EMAIL PROTECTED] (Tom Phoenix) wrote: > On Jan 24, 2008 9:07 AM, <[EMAIL PROTECTED]> wrote: > > > I'd like to get the number of keys in hash of hashes. I know that I > > can do something like $count = keys( %myHash ), but how would I go > > about finding the number of keys i

Re: Return number of keys in a hash of hash? Looping through "sub hash"?

2008-01-24 Thread Tom Phoenix
On Jan 24, 2008 9:07 AM, <[EMAIL PROTECTED]> wrote: > I'd like to get the number of keys in hash of hashes. I know that I > can do something like $count = keys( %myHash ), but how would I go > about finding the number of keys in a sub-hash? my $count = keys %{ $sub_hash_reference }; You can

Return number of keys in a hash of hash? Looping through "sub hash"?

2008-01-24 Thread pzimmermann
I'd like to get the number of keys in hash of hashes. I know that I can do something like $count = keys( %myHash ), but how would I go about finding the number of keys in a sub-hash? Alternately, how could I loop through keys in a hash of a hash? My hash look like: -Part Number 1 --Type 1 (key)

Re: Looping through lines stored in a scalar

2008-01-03 Thread Jean-Rene David
* Paul Johnson [2008.01.01 22:10]: > The most direct analogy would be to use an > in-memory file: > > open my $fh, "<", \$scalar; > print while <$fh>; Very nice. Thanks. I didn't understand what John and Chas were trying to say until I saw the term "in-memory file". Exactly the kind of stuff I

Re: Looping through lines stored in a scalar

2008-01-01 Thread John W. Krahn
Chas. Owens wrote: If you have a recent enough version of Perl* you can say open my $fh, "<", \$scalar or die "could not attach a file handle to \$scalar: $!"; while (my $line = <$fh>) { chomp($line); #do stuff with $line } * 5.8 can do this, but I am not sure about 5.6.* perldo

Re: Looping through lines stored in a scalar

2008-01-01 Thread Paul Johnson
On Mon, Dec 31, 2007 at 05:56:35PM -0500, Jean-Rene David wrote: > I wonder what idioms are available to loop through > the lines stored in a scalar variable. I guess I'm > looking for something analogous to these idioms > for files and arrays respectively: > > while() { > # do stuff > } > > for

Re: Looping through lines stored in a scalar

2008-01-01 Thread Chas. Owens
On Jan 1, 2008 12:21 PM, yitzle <[EMAIL PROTECTED]> wrote: > You can skip the array assignment and just do: > > foreach ( split "\n", $scalar ) { > ... > } > > I predict a reply that uses map()... though I think that using a map > isn't really another solution, but just an alternative to the for >

Re: Looping through lines stored in a scalar

2008-01-01 Thread John W. Krahn
Jean-Rene David wrote: Hi, Hello, I wonder what idioms are available to loop through the lines stored in a scalar variable. I guess I'm looking for something analogous to these idioms for files and arrays respectively: while() { # do stuff } open FH, '<', \$scalar or die "Cannot open \$sca

Re: Looping through lines stored in a scalar

2008-01-01 Thread Rob Dixon
Jean-Rene David wrote: Hi, I wonder what idioms are available to loop through the lines stored in a scalar variable. I guess I'm looking for something analogous to these idioms for files and arrays respectively: while() { # do stuff } foreach (@array) { # do stuff } When I had to do this I sp

Re: Looping through lines stored in a scalar

2008-01-01 Thread yitzle
You can skip the array assignment and just do: foreach ( split "\n", $scalar ) { ... } I predict a reply that uses map()... though I think that using a map isn't really another solution, but just an alternative to the for loop. map {stuff}, split "\n", $scalar; But I think the answer is basica

Re: Looping through lines stored in a scalar

2008-01-01 Thread Tom Phoenix
On Dec 31, 2007 2:56 PM, Jean-Rene David <[EMAIL PROTECTED]> wrote: > When I had to do this I split the scalar in an > array: > > @array = split "\n", $scalar; > foreach (@array) { > # do stuff > } > > What would be some other ways to do this? (This is > purely curiosity.) This type of curiosity

Re: Looping through lines stored in a scalar

2008-01-01 Thread Chas. Owens
On Dec 31, 2007 5:56 PM, Jean-Rene David <[EMAIL PROTECTED]> wrote: > Hi, > > I wonder what idioms are available to loop through > the lines stored in a scalar variable. I guess I'm > looking for something analogous to these idioms > for files and arrays respectively: > > while() { > # do stuff > }

Looping through lines stored in a scalar

2008-01-01 Thread Jean-Rene David
Hi, I wonder what idioms are available to loop through the lines stored in a scalar variable. I guess I'm looking for something analogous to these idioms for files and arrays respectively: while() { # do stuff } foreach (@array) { # do stuff } When I had to do this I split the scalar in an arra

Re: looping through a file

2007-05-09 Thread Chas Owens
On 5/9/07, Rob Dixon <[EMAIL PROTECTED]> wrote: Steve Bertrand wrote: >> but if they appear in the file in a different sequence then you also >> need to rewind and start looking at the beginning of the file once >> again like this: >> >> ID: >> foreach my $prime_id ( @id_hits ) { >>while (

Re: looping through a file

2007-05-09 Thread Rob Dixon
Steve Bertrand wrote: but if they appear in the file in a different sequence then you also need to rewind and start looking at the beginning of the file once again like this: ID: foreach my $prime_id ( @id_hits ) { while ( my $line = <$AFILE> ) { if ( $line =~ /$prime_id/ ) { pr

Re: looping through a file

2007-05-09 Thread Steve Bertrand
> but if they appear in the file in a different sequence then you also > need to rewind and start looking at the beginning of the file once > again like this: > > ID: > foreach my $prime_id ( @id_hits ) { >while ( my $line = <$AFILE> ) { > if ( $line =~ /$prime_id/ ) { >print "

Re: looping through a file

2007-05-08 Thread Robert Hicks
Rob Dixon wrote: Robert Hicks wrote: I decided to back up a bit and try a more simple routine. I have the array @id_hits populated and I can search the log for the line and print it. The problem is it only finds the first match and that is it. foreach my $prime_id ( @id_hits ) { while ( m

Re: looping through a file

2007-05-08 Thread Rob Dixon
Jeff Pang wrote: -Original Message- From: [EMAIL PROTECTED] Sent: May 8, 2007 9:54 PM To: [EMAIL PROTECTED] Cc: beginners@perl.org Subject: Re: looping through a file my @lines = <$AFILE>; foreach my $prime_id ( @id_hits ) { foreach my $line( @lines ) { if (

Re: looping through a file

2007-05-08 Thread Rob Dixon
Robert Hicks wrote: I decided to back up a bit and try a more simple routine. I have the array @id_hits populated and I can search the log for the line and print it. The problem is it only finds the first match and that is it. foreach my $prime_id ( @id_hits ) { while ( my $line = <$AFILE>

Re: looping through a file

2007-05-08 Thread Jeff Pang
-Original Message- >From: [EMAIL PROTECTED] >Sent: May 8, 2007 9:54 PM >To: [EMAIL PROTECTED] >Cc: beginners@perl.org >Subject: Re: looping through a file >my @lines = <$AFILE>; >foreach my $prime_id ( @id_hits ) { > foreach my $line( @lines ) { >

Re: looping through a file

2007-05-08 Thread yaron
> To: beginners@perl.org Sent: Tuesday, May 8, 2007 4:39:12 PM (GMT+0200) Auto-Detected Subject: Re: looping through a file I decided to back up a bit and try a more simple routine. I have the array @id_hits populated and I can search the log for the line and print it. The problem is it only f

Re: looping through a file

2007-05-08 Thread Robert Hicks
I decided to back up a bit and try a more simple routine. I have the array @id_hits populated and I can search the log for the line and print it. The problem is it only finds the first match and that is it. foreach my $prime_id ( @id_hits ) { while ( my $line = <$AFILE> ) { if ( $li

Re: looping through a file

2007-05-08 Thread Dr.Ruud
Robert Hicks schreef: > open my $IFILE, '<', $IDFILE || die "Could not open $IDFILE: $!"; This doesn't mean what you assume it does. It is a mix up of: open(my $IFILE, '<', $IDFILE) || die "Could not open $IDFILE: $!"; and open my $IFILE, '<', $IDFILE or die "Could not open $IDFILE: $!";

RE: looping through a file

2007-05-07 Thread Craig Schneider
Hi Guys Following is a log file extract which I desperately need to covert to coma separated for an entire logile called access.log (squid proxy log) for reporting purposes. There has been some internet surfing abuse on a client's network. 1178606984.937 1 192.168.1.55 TCP_DENIED/407 1904 PO

Re: looping through a file

2007-05-07 Thread Robert Hicks
Chas Owens wrote: On 5/7/07, Robert Hicks <[EMAIL PROTECTED]> wrote: snip I think part of the problem is the 'shift'ing that I was doing. I am looking into that. Basically I was shift'ing the @log out of existence after the first pass. snip That sounds like a viable candidate for the warning a

Re: looping through a file

2007-05-07 Thread Chas Owens
On 5/7/07, Robert Hicks <[EMAIL PROTECTED]> wrote: snip I think part of the problem is the 'shift'ing that I was doing. I am looking into that. Basically I was shift'ing the @log out of existence after the first pass. snip That sounds like a viable candidate for the warning as well. snip > A

Re: looping through a file

2007-05-07 Thread Robert Hicks
Chas Owens wrote: On 5/7/07, Robert Hicks <[EMAIL PROTECTED]> wrote: I have one file that contains a log. I do a substr to get the information out of that and push it into an array. I have a second file that contain another log. I need to loop through the items in the array and find them in thi

Re: looping through a file

2007-05-07 Thread Chas Owens
On 5/7/07, Robert Hicks <[EMAIL PROTECTED]> wrote: I have one file that contains a log. I do a substr to get the information out of that and push it into an array. I have a second file that contain another log. I need to loop through the items in the array and find them in this log. Once I find

looping through a file

2007-05-07 Thread Robert Hicks
I have one file that contains a log. I do a substr to get the information out of that and push it into an array. I have a second file that contain another log. I need to loop through the items in the array and find them in this log. Once I find the line that the id is on, I need the next line

Re: looping through complicated hashes..

2006-09-08 Thread Jack Faley ( The Tao of Jack )
On 9/8/06, Charles K. Clarkson <[EMAIL PROTECTED]> wrote: Michael Alipio wrote: : ignore this one.. I've already figured out how. Why not post your solution for the archives? Someone else may run across your question during a search and will not know the answer you found. HTH, Charles K.

RE: looping through complicated hashes..

2006-09-08 Thread Charles K. Clarkson
Michael Alipio wrote: : ignore this one.. I've already figured out how. Why not post your solution for the archives? Someone else may run across your question during a search and will not know the answer you found. HTH, Charles K. Clarkson -- Mobile Homes Specialist Free Market Advocate We

Re: looping through complicated hashes..

2006-09-07 Thread Ashok Varma
Hi Michael, Following is one way ... Here is am assuming that you have dumped that data into a array named '@your_array' which contains each line in array references(array of arrays). $table = new HTML::T

Re: looping through complicated hashes..

2006-09-07 Thread Michael Alipio
ignore this one.. I've already figured out how. thanks. --- Michael Alipio <[EMAIL PROTECTED]> wrote: > Hi, > > I have an input file with 7 columns each line. Words > are separated with 1 or more spaces.. > Now, I want each of these lines placed into > HTML::Table's rows. > > The HTML::Table ha

looping through complicated hashes..

2006-09-07 Thread Michael Alipio
Hi, I have an input file with 7 columns each line. Words are separated with 1 or more spaces.. Now, I want each of these lines placed into HTML::Table's rows. The HTML::Table has something like this. each row (with 7 cells) is encolsed with []. I want each row, populated with each line in my inpu

Re: looping over an array of hashes

2006-04-28 Thread Mr. Shawn H. Corey
On Fri, 2006-28-04 at 15:40 +0100, Graeme McLaren wrote: > Hi all, I need to loop over an array of hashes and assign a new hashref if a > condition is met: > > I have a scalar which contains an array of hashes: > > $locations = [ > { > 'location_name' => 'Fionas House', >

looping over an array of hashes

2006-04-28 Thread Graeme McLaren
Hi all, I need to loop over an array of hashes and assign a new hashref if a condition is met: I have a scalar which contains an array of hashes: $locations = [ { 'location_name' => 'Fionas House', 'location_id' => '0027' }, {

Re: spreadsheets to ldif (trouble looping through array)..

2005-09-17 Thread John W. Krahn
Harold Castro wrote: > > #This line is too tricky for me, all I know is that it > has a ternary hook operator which returns $_ if the > expression my @fields = map length() is true, > otherwise, substitute empty fields with 'NA'. I looked > into perldoc -f map as well as length() and as far as > I

  1   2   3   >