[27563] in Perl-Users-Digest

home help back first fref pref prev next nref lref last post

Perl-Users Digest, Issue: 9104 Volume: 10

daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Wed Mar 29 21:05:38 2006

Date: Wed, 29 Mar 2006 18:05:05 -0800 (PST)
From: Perl-Users Digest <Perl-Users-Request@ruby.OCE.ORST.EDU>
To: Perl-Users@ruby.OCE.ORST.EDU (Perl-Users Digest)

Perl-Users Digest           Wed, 29 Mar 2006     Volume: 10 Number: 9104

Today's topics:
    Re: Find duplicates in a dat file <tadmc@augustmail.com>
        for loop is not going to all array elements <bhoppe@ti.com>
    Re: for loop is not going to all array elements <1usa@llenroc.ude.invalid>
    Re: for loop is not going to all array elements <jgibson@mail.arc.nasa.gov>
    Re: Help calling perl from gnu make on windows <Random@Task.be>
    Re: Help calling perl from gnu make on windows <rvtol+news@isolution.nl>
    Re: Help calling perl from gnu make on windows <1usa@llenroc.ude.invalid>
        Digest Administrivia (Last modified: 6 Apr 01) (Perl-Users-Digest Admin)

----------------------------------------------------------------------

Date: Wed, 29 Mar 2006 16:26:08 -0600
From: Tad McClellan <tadmc@augustmail.com>
Subject: Re: Find duplicates in a dat file
Message-Id: <slrne2m2c0.5nt.tadmc@magna.augustmail.com>

axel@white-eagle.invalid.uk <axel@white-eagle.invalid.uk> wrote:
> Tami@des.com wrote:
>>>If you concatenated all the files into a single file, this should work

> Or you could pipe the files into a perl script:
> 
> 	cat *.dat | myscript.pl
> 
> and read the data from standard input.


Or you could put the filenames as command line arguments
and read the data from the diamond operator.

   myscript.pl *.dat

(well, you could if you had a sensible shell.)


-- 
    Tad McClellan                          SGML consulting
    tadmc@augustmail.com                   Perl programming
    Fort Worth, Texas


------------------------------

Date: Wed, 29 Mar 2006 17:08:08 -0600
From: Brandon Hoppe <bhoppe@ti.com>
Subject: for loop is not going to all array elements
Message-Id: <e0f40o$7nc$1@home.itg.ti.com>

Hi,

I have a for loop that loops that an array. Inside the for loop, I push 
more elements onto the array if needed, but the loop is stopping at the 
original end of the array and not looping thru the new additions.

Basicall, this is what I have:

$line = "-name SSCC34234342 -views ,Datasheet,Verilog!BREAK!";
@wow = ();
push(@wow, $line);

foreach $inline (@wow) {
   print "LINE: $inline\n";

   if($inline =~ /SSCC/) {
      $newline = $inline;
      $newline =~ s/SSCC/BRGS/;
      push(@wow, $newline);
   }
}

Now this code above works. It prints the line with SSCC and then prints 
the line with BRGS.

But in a large piece of code, I have a similar loop. Several other 
things happen inside the loop, so I'm not sure what could be wrong.

As a debug method, just before the end brace of the foreach loop I added 
a simple foreach loop that prints out all the elements of the @wow 
array. This prints out all the newly added elements and the original 
array. So in the case above it prints out the SSCC line and the BRGS 
line. So the array is correctly updated from what I take, its just that 
the original foreach loop isn't going to the new element.

Any ideas? I've tried to add as much info as possible. The loop is 
pretty large and part of a cgi script so its hard to cut out and test 
just the for loop with a debugger.


------------------------------

Date: Wed, 29 Mar 2006 23:23:08 GMT
From: "A. Sinan Unur" <1usa@llenroc.ude.invalid>
Subject: Re: for loop is not going to all array elements
Message-Id: <Xns9795BB27BAC6Aasu1cornelledu@127.0.0.1>

Brandon Hoppe <bhoppe@ti.com> wrote in news:e0f40o$7nc$1
@home.itg.ti.com:

> I have a for loop that loops that an array. Inside the for loop, I
> push more elements onto the array if needed, but the loop is stopping 
> at the original end of the array and not looping thru the new 
> additions.

Well, don't do that.

From perldoc perlsyn, "Foreach Loops":

   If any part of LIST is an array, "foreach" will get very confused if 
   you add or remove elements within the loop body, for example with 
   "splice". So don't do that.

I would question the need to modify an array while looping over it using 
a foreach loop.

On the other hand, you should be able to use a C-style for loop where 
you test against the array size in each iteration:

for (my $i = 0; $i < @array, ++$i ) {

# do something with $array[$i]

}

You'll need to make sure this does not turn into an infinite loop.

Sinan

-- 
A. Sinan Unur <1usa@llenroc.ude.invalid>
(remove .invalid and reverse each component for email address)

comp.lang.perl.misc guidelines on the WWW:
http://augustmail.com/~tadmc/clpmisc/clpmisc_guidelines.html



------------------------------

Date: Wed, 29 Mar 2006 17:23:05 -0800
From: Jim Gibson <jgibson@mail.arc.nasa.gov>
Subject: Re: for loop is not going to all array elements
Message-Id: <290320061723055560%jgibson@mail.arc.nasa.gov>

In article <e0f40o$7nc$1@home.itg.ti.com>, Brandon Hoppe
<bhoppe@ti.com> wrote:

> Hi,
> 
> I have a for loop that loops that an array. Inside the for loop, I push 
> more elements onto the array if needed, but the loop is stopping at the 
> original end of the array and not looping thru the new additions.
> 
> Basicall, this is what I have:
> 
> $line = "-name SSCC34234342 -views ,Datasheet,Verilog!BREAK!";
> @wow = ();
> push(@wow, $line);
> 
> foreach $inline (@wow) {
>    print "LINE: $inline\n";
> 
>    if($inline =~ /SSCC/) {
>       $newline = $inline;
>       $newline =~ s/SSCC/BRGS/;
>       push(@wow, $newline);
>    }
> }

Why don't you copy the array first, then iterate over the array adding
lines to the copy as needed (untested):

push(@wow, $line);
my @wow2 = @wow;

foreach $inline (@wow) {
   print "LINE: $inline\n";

   if($inline =~ /SSCC/) {
      $newline = $inline;
      $newline =~ s/SSCC/BRGS/;
      push(@wow2, $newline);
   }
}

Do you need to reprocess the lines added?

 Posted Via Usenet.com Premium Usenet Newsgroup Services
----------------------------------------------------------
    ** SPEED ** RETENTION ** COMPLETION ** ANONYMITY **
----------------------------------------------------------        
                http://www.usenet.com


------------------------------

Date: Wed, 29 Mar 2006 15:13:43 -0500
From: Random Task <Random@Task.be>
Subject: Re: Help calling perl from gnu make on windows
Message-Id: <442AEA77.70103@Task.be>

Unfortunately yes ...

I have tried

	<"some exec filename with space"> -help

which executes fine ... but as soon as the 2nd argument has spaces i.e.

	<"command"> <"arg1_with_spaces">

Everything i see on google says don't uses spaces ...

Any other suggestions?

Jim



Dr.Ruud wrote:
> Random Task schreef:
> 
>> I am calling perl from gnu make on windows and I am having a problem
>> with "arguments with spaces".
> 
> Did you try to put "" around them?
> 


------------------------------

Date: Wed, 29 Mar 2006 22:51:05 +0200
From: "Dr.Ruud" <rvtol+news@isolution.nl>
Subject: Re: Help calling perl from gnu make on windows
Message-Id: <e0f3ec.1g4.1@news.isolution.nl>

Random Task schreef:
> Dr.Ruud:
>> Random Task:

Please don't top-post.

>>> I am calling perl from gnu make on windows and I am having a problem
>>> with "arguments with spaces".
>>
>> Did you try to put "" around them?
>
> Unfortunately yes ...  I have tried
>   <"some exec filename with space"> -help
> which executes fine ... but as soon as the 2nd argument has spaces
> i.e.
>   <"command"> <"arg1_with_spaces">
> Everything i see on google says don't uses spaces ...
> Any other suggestions?

I meant in your build rule. The error message is about "C:/Program\",
and I see that part only in your build rule.

You can also use the 8.3 name of "C:/Program Files", often
"C:/PROGRA~1", see

   dir c:\p* /ad/x

from a DOS-prompt.

-- 
Affijn, Ruud

"Gewoon is een tijger."
echo 014C8A26C5DB87DBE85A93DBF |perl -pe 'tr/0-9A-F/JunkshoP cartel,/'



------------------------------

Date: Wed, 29 Mar 2006 21:07:35 GMT
From: "A. Sinan Unur" <1usa@llenroc.ude.invalid>
Subject: Re: Help calling perl from gnu make on windows
Message-Id: <Xns9795A42C95137asu1cornelledu@127.0.0.1>

Random Task <Random@Task.be> wrote in news:442AEA77.70103@Task.be:

> Unfortunately yes ...

Yes what? Oh, you are top-posting, please don't do that.

> I have tried
> 
>      <"some exec filename with space"> -help
> 
> which executes fine ... but as soon as the 2nd argument has spaces
> i.e.
> 
>      <"command"> <"arg1_with_spaces">
> 

D:\Home\asu1\UseNet\clpmisc\dat> cat Makefile
main:
        perl "C:/Program Files/test.pl"


D:\Home\asu1\UseNet\clpmisc\dat> make
perl "C:/Program Files/test.pl"
Can't open perl script "C:/Program Files/test.pl": No such file or 
directory
make: *** [main] Error 2

D:\Home\asu1\UseNet\clpmisc\dat> make -v
GNU Make 3.80

True, the file does not exist but this demonstrates that the argument is 
passed correctly to perl.

Sinan
-- 
A. Sinan Unur <1usa@llenroc.ude.invalid>
(remove .invalid and reverse each component for email address)

comp.lang.perl.misc guidelines on the WWW:
http://augustmail.com/~tadmc/clpmisc/clpmisc_guidelines.html



------------------------------

Date: 6 Apr 2001 21:33:47 GMT (Last modified)
From: Perl-Users-Request@ruby.oce.orst.edu (Perl-Users-Digest Admin) 
Subject: Digest Administrivia (Last modified: 6 Apr 01)
Message-Id: <null>


Administrivia:

#The Perl-Users Digest is a retransmission of the USENET newsgroup
#comp.lang.perl.misc.  For subscription or unsubscription requests, send
#the single line:
#
#	subscribe perl-users
#or:
#	unsubscribe perl-users
#
#to almanac@ruby.oce.orst.edu.  

NOTE: due to the current flood of worm email banging on ruby, the smtp
server on ruby has been shut off until further notice. 

To submit articles to comp.lang.perl.announce, send your article to
clpa@perl.com.

#To request back copies (available for a week or so), send your request
#to almanac@ruby.oce.orst.edu with the command "send perl-users x.y",
#where x is the volume number and y is the issue number.

#For other requests pertaining to the digest, send mail to
#perl-users-request@ruby.oce.orst.edu. Do not waste your time or mine
#sending perl questions to the -request address, I don't have time to
#answer them even if I did know the answer.


------------------------------
End of Perl-Users Digest V10 Issue 9104
***************************************


home help back first fref pref prev next nref lref last post