[22794] in Perl-Users-Digest

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

Perl-Users Digest, Issue: 5015 Volume: 10

daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Tue May 20 21:06:04 2003

Date: Tue, 20 May 2003 18:05:13 -0700 (PDT)
From: Perl-Users Digest <Perl-Users-Request@ruby.OCE.ORST.EDU>
To: Perl-Users@ruby.OCE.ORST.EDU (Perl-Users Digest)

Perl-Users Digest           Tue, 20 May 2003     Volume: 10 Number: 5015

Today's topics:
    Re: advice re perl modules <willis_31_40@yahoo.com>
        Another regex problem <zak@mighty.co.za>
    Re: awstats ignores HostAliases if using %virtualname <abigail@abigail.nl>
        calling an exe file <johnsmith@yahoo.com>
    Re: calling an exe file <willis_31_40@yahoo.com>
        Can't install HTML::Request::Common in Cygwin!  Any ide (Steven W. Buehler, B.A.)
    Re: Close html page <willis_31_40@yahoo.com>
    Re: copying files between two directories <bwalton@rochester.rr.com>
        error handling on file open <Rene.Scheibe@gmx.net>
    Re: error handling on file open <willis_31_40@yahoo.com>
    Re: error handling on file open <jaspax@u.washington.edu>
    Re: error handling on file open <michael.p.broida@boeing.com>
    Re: GD::Graph error "libgd was not built with FreeType  <mgjv@tradingpost.com.au>
    Re: Get file extensions by regular expression <bigj@kamelfreund.de>
    Re: making scalar variables from array elements, put in (Jay Tilton)
    Re: newbie needs help please <n_joeller@sharblbaziilyar.com>
    Re: Perl: Regex help request (Malcolm Dew-Jones)
        While loops and arrays (Jday)
    Re: While loops and arrays <willis_31_40@yahoo.com>
    Re: While loops and arrays <noreply@gunnar.cc>
    Re: While loops and arrays <mbudash@sonic.net>
    Re: While loops and arrays <michael.p.broida@boeing.com>
        Digest Administrivia (Last modified: 6 Apr 01) (Perl-Users-Digest Admin)

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

Date: Tue, 20 May 2003 22:58:57 GMT
From: w i l l <willis_31_40@yahoo.com>
Subject: Re: advice re perl modules
Message-Id: <giclcv0ssoo9i0l0lii6j1669cumdobrcp@4ax.com>

On Tue, 20 May 2003 09:26:31 -0700, Max Waterman <maxw@sgi.com> wrote:

>Hi,
>
>I have developed a perl application on one machine which has perl v5.6.1,
>and I have used CPAN.pm to install the require modules.
>
>I now need to install the application on another machine which has either
>perl 5.004_05 or 5.004_02, but is missing a fair number of the perl
>modules my application needs.
>
>I can install perl modules, but I should not update any that are already
>installed since other applications rely on them.
>
>I would like to be able to create a self contained application so that it
>doesn't break when someone changes the machine's perl installation. I
>guess this is the same as if I had no root privs at all.
>
>Can someone tell me how I can do this?
>
>If it were a binary application, I would use 'ldd' and 'rld' to locate
>the libs the app uses, and copy them into a local directory, etc etc. Not
>sure even how to find out what the full path of a perl module my app
>'use's let alone make sure the app uses local ones.
>
>Thanks.
>
>Max.
>

I think someone beat me to the punch, but just install the modules in
their own specific directory away from the other modules. I'd clear
out the @INC dir then
use lib qw(/path/to/my/modules);
so that the application is only looking in that specific directory for
those modules. You will have no problems that way.

However, you may have problems with trying to run new versions of
modules with old versions of perl. Some modules need to get updated
with newer versions of perl.

anyway, there's my $.02

w i l l


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

Date: Wed, 21 May 2003 02:44:39 +0200
From: Zak McGregor <zak@mighty.co.za>
Subject: Another regex problem
Message-Id: <baei5l$ihi$1@ctb-nnrp2.saix.net>

Hi guys

I have input of the form
<[command option]some text[/command]>

where "some text" may contain further <[command option]other
text[/command]> syntax. Each "command" could be different as well, and
they can be nested to arbitrary depths. I've tried to use a regex to
handle this, but it is proving difficult, especially when some of the
"arbittrary text" contains "[" or "]" characters. apparently
Parse::RecDescent should be my next step, but it is proving awfully tough
to get into. Am I wasting time trying to get a regex to do what I want -
the FAQ seems to suggest that that is the case. If i am wasting time,
does anyone have any good references to Parse::RecDescent tutorials or
other information on implementing it please?

An example:

$parsetext=<<"XXX";

<[ALIAS limit]20[/ALIAS]>
<[ALIAS offset]0[/ALIAS]>
<[SELECT dbname=database1]
select * from some_table where
field1='[[:<:]]<[UVAL]keyword[/UVAL]>[[:>:]]'
[/SELECT]>
<[LEVEL 1]

<[R]
dfgsdfgsdfg
[/R]>

[/LEVEL]>

XXX

while (defined($parsetext) && $parsetext=~s/
<\[([^\ ]*)
((?<=\\)\]|.*?)
(?<!\\)\]
(.*?)
(?<!\\)\[\/\1\]>
/printit($1, $2, $3)
/sex) {

#;;;

}


__END__

where UVAL, SELECT, ALIAS etc. are all commands, and "limit", "offset",
"dbname=database1" etc. are all options.

the printit subroutine merely prints the various portions.

The output is almost as required, except the innermost bits are not being
found first, which is not what I would expect, or want.

Thanks

Ciao

Zak

--
========================================================================
http://www.carfolio.com/        Searchable database of 10 000+ car specs
========================================================================


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

Date: 20 May 2003 22:41:30 GMT
From: Abigail <abigail@abigail.nl>
Subject: Re: awstats ignores HostAliases if using %virtualname
Message-Id: <slrnbclboq.kuj.abigail@alexandra.abigail.nl>

gooze (g000ze@gmx.net) wrote on MMMDXLIX September MCMXCIII in
<URL:news:e09c7315.0305200328.1927c5df@posting.google.com>:
||  
||  Now my question: Does somebody know awstats? Is somebody able to
||  modify awstats so that awstats cares about both fields, the SiteDomain
||  AND the HostAliases, although the "%virtualname" value is in the
||  LogFormat field?


Where is your Perl question?



Abigail
-- 
perl5.004 -wMMath::BigInt -e'$^V=Math::BigInt->new(qq]$^F$^W783$[$%9889$^F47]
 .qq]$|88768$^W596577669$%$^W5$^F3364$[$^W$^F$|838747$[8889739$%$|$^F673$%$^W]
 .qq]98$^F76777$=56]);$^U=substr($]=>$|=>5)*(q.25..($^W=@^V))=>do{print+chr$^V
%$^U;$^V/=$^U}while$^V!=$^W'


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

Date: Tue, 20 May 2003 23:19:52 GMT
From: "Anthony" <johnsmith@yahoo.com>
Subject: calling an exe file
Message-Id: <3ecab807$1@news.syd.ip.net.au>

hi


Am still a newie to perl
How do i run an exe. Is there a command.

once the script is finished running
i need to alert an application that files are waiting in c:\test. The
application has an exe test.exe and will pick the waiting files in c:\test.
How do i call the test.exe


tony





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

Date: Tue, 20 May 2003 23:24:01 GMT
From: w i l l <willis_31_40@yahoo.com>
Subject: Re: calling an exe file
Message-Id: <16elcvsglf6okadjff3mqmegcsm8295e4c@4ax.com>

On Tue, 20 May 2003 23:19:52 GMT, "Anthony" <johnsmith@yahoo.com>
wrote:

>hi
>
>
>Am still a newie to perl
>How do i run an exe. Is there a command.
>
>once the script is finished running
>i need to alert an application that files are waiting in c:\test. The
>application has an exe test.exe and will pick the waiting files in c:\test.
>How do i call the test.exe
>
>
>tony
>
>



system('c:/test/test.exe');


-------

w i l l


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

Date: 20 May 2003 15:21:03 -0700
From: steven@sanctuaryweb.org (Steven W. Buehler, B.A.)
Subject: Can't install HTML::Request::Common in Cygwin!  Any ideas??
Message-Id: <f76e1dcb.0305201421.5fdcbb9c@posting.google.com>

Running Cygwin, Perl 5.8.0.  HTML::Request::Common refuses to install
and produces the following test failures.  Any ideas how to fix?

SWB

Failed Test      Stat Wstat Total Fail  Failed  List of Failed
-------------------------------------------------------------------------------
local/http-get.t  119 30464    19   19 100.00%  1-19
local/http.t      119 30464    18   18 100.00%  1-18
robot/ua-get.t                  7    5  71.43%  1-3 5 7
robot/ua.t                      7    5  71.43%  1-3 5 7
Failed 4/26 test scripts, 84.62% okay. 47/343 subtests failed, 86.30%
okay.


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

Date: Tue, 20 May 2003 23:02:56 GMT
From: w i l l <willis_31_40@yahoo.com>
Subject: Re: Close html page
Message-Id: <rrclcv4tftsfjgqhk27u475f8544pf1opo@4ax.com>

On Tue, 20 May 2003 10:46:39 -0700, "Chris" <chris_12003@yahoo.com>
wrote:

>I have the following in my code to begin my html page
>
>print "Content-type: text/html\n";
>
>Is there another statement I can use that'll close the page so that I can
>issue another print "Content..., actually I need to send a cookie header
>later in my code and it isn't working because the header was already sent.
>
>Thanks,
>Chris
>


use CGI; #!!!!!!

# send header to broswer


my $c = new CGI;
my $cookie = $c->cookie(-name=>"Foo", -value=>"BAR", -path=>"/",
-expires=>'+2M',);
print $c->header(-cookie=>$cookie);

Good luck
w i l l


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

Date: Wed, 21 May 2003 00:41:54 GMT
From: Bob Walton <bwalton@rochester.rr.com>
Subject: Re: copying files between two directories
Message-Id: <3ECACA02.7080200@rochester.rr.com>

Naina wrote:

 ...

> Iam trying to copy files existing under two different root
> directories.Help needed with also if any Attributes  can be used to
> get all files with some extension. Any suggestions would be welcome.
 ...

> Naina
> 

If you:

     use File::Find;
and
     use File::Copy;

things should go well with the task you describe.

-- 
Bob Walton



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

Date: Wed, 21 May 2003 00:57:19 +0200
From: "Rene Scheibe" <Rene.Scheibe@gmx.net>
Subject: error handling on file open
Message-Id: <baebsj$slmfu$1@ID-65612.news.dfncis.de>

i have some questions about handling errors
when opening files. for example you can do

open (FILE, "filenpath") or die("cannot open file");

my questions:
1) what is the difference using "or" or "||"?

2) how can i run more than one command after "or"?
    the following doesnt work:
open (FILE, "filepath") or {
print "cannot open file";
print "exiting script";
exit; }

thanks rene




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

Date: Tue, 20 May 2003 23:06:45 GMT
From: w i l l <willis_31_40@yahoo.com>
Subject: Re: error handling on file open
Message-Id: <j5dlcv09o561hl6d43lrtf1ah5lsvfv9u2@4ax.com>

On Wed, 21 May 2003 00:57:19 +0200, "Rene Scheibe"
<Rene.Scheibe@gmx.net> wrote:

>i have some questions about handling errors
>when opening files. for example you can do
>
>open (FILE, "filenpath") or die("cannot open file");
>
>my questions:
>1) what is the difference using "or" or "||"?
>
>2) how can i run more than one command after "or"?
>    the following doesnt work:
>open (FILE, "filepath") or {
>print "cannot open file";
>print "exiting script";
>exit; }
>
>thanks rene
>



if (open(FILE,"path")) {

do stuff;

}
else {

do something else;

}


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

Date: Tue, 20 May 2003 16:50:58 -0700
From: JS Bangs <jaspax@u.washington.edu>
Subject: Re: error handling on file open
Message-Id: <Pine.A41.4.55.0305201648360.96932@dante05.u.washington.edu>

Rene Scheibe sikyal:

> i have some questions about handling errors
> when opening files. for example you can do
>
> open (FILE, "filenpath") or die("cannot open file");
>
> my questions:
> 1) what is the difference using "or" or "||"?

Mostly just precedence. English "or" has a much lower precedence than
"||". My advice: go with "or" most of the time, and clear up precedence
with parentheses if you need to. Besides, if your code depends that
closely on precedence, it will be very hard to read.

> 2) how can i run more than one command after "or"?
>     the following doesnt work:
> open (FILE, "filepath") or {
> print "cannot open file";
> print "exiting script";
> exit; }

open (FILE, "filepath") or do {};


Jesse S. Bangs jaspax@u.washington.edu
http://students.washington.edu/jaspax/
http://students.washington.edu/jaspax/blog

Jesus asked them, "Who do you say that I am?"

And they answered, "You are the eschatological manifestation of the ground
of our being, the kerygma in which we find the ultimate meaning of our
interpersonal relationship."

And Jesus said, "What?"


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

Date: Wed, 21 May 2003 00:01:23 GMT
From: "Michael P. Broida" <michael.p.broida@boeing.com>
Subject: Re: error handling on file open
Message-Id: <3ECAC1D3.7EA64E0C@boeing.com>

Rene Scheibe wrote:
> 
> i have some questions about handling errors
> when opening files. for example you can do
> 
> open (FILE, "filenpath") or die("cannot open file");
> 
> my questions:
> 1) what is the difference using "or" or "||"?

	Using "||" can fail due to the operator precedence levels
	if you weren't using () on the "open" portion of that line.

	   open FILE, "filenpath" || die("cannot open file");

	is BAD in that it performs the "||" operator before the ","
	operator that builds the arg list for the "open".

	As long as you're using the () on "open", you can use "||"
	or "or".  Perhaps safest to use the "or" anyway because it
	has the very lowest operator precedence level.

	This is specifically mentioned in the "Camel" book, Chapter
	2, under the heading "Logical, and, or, and xor" (page 94
	in my edition).  (I'm not trying to imply you should have
	looked there; just pointing you there for more info. <grin>)

		Mike


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

Date: Wed, 21 May 2003 00:44:14 GMT
From: Martien Verbruggen <mgjv@tradingpost.com.au>
Subject: Re: GD::Graph error "libgd was not built with FreeType Font"
Message-Id: <slrnbcliuu.88a.mgjv@verbruggen.comdyn.com.au>

On 19 May 2003 13:42:26 -0700,
	kathygao <kathygao@lucent.com> wrote:
> I encountered a problem when using GD::Graph module.. I try to change
> font size in my code, but got following error message ..
> "libgd was not built with FreeType font.."

That is not a GD::Graph error, but an error from the libgd library
which is used by the GD module. It means what it says: your libgd was
not compiled with Freetype support. This means that you cannot use TTF
fonts in GD::Graph or GD. You need to compile a libgd with
freetype support, recompiled GD with the identical settings, and
install. That should fix it.

Until then, you are limited to internal GD fonts, and they are not
sizeable.

Also see the can_do_ttf() method in GD::Graph and GD::Text.

Martien
-- 
                        | 
Martien Verbruggen      | Failure is not an option. It comes bundled
Trading Post Australia  | with your Microsoft product.
                        | 


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

Date: Tue, 20 May 2003 22:24:28 +0200
From: "Janek Schleicher" <bigj@kamelfreund.de>
Subject: Re: Get file extensions by regular expression
Message-Id: <pan.2003.05.20.20.22.28.386417@kamelfreund.de>

William Goedicke wrote at Tue, 20 May 2003 16:25:10 +0000:

>> i have a filename and want to get its extension.
> 
> I think I'd use split.  Here's some untested code.
> 
> @fn_pieces = split "\.", $fn;
                     ^  ^
I believe, it would be better to use either
'\.'
or
/\./
 .
"\." is evaluated first to "." (as string) and then to /./ as regexp,
that is very different from /\./ 

> $extension = $fn_pieces[-1];


Cheerio,
Janek




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

Date: Wed, 21 May 2003 00:22:42 GMT
From: tiltonj@erols.com (Jay Tilton)
Subject: Re: making scalar variables from array elements, put into table
Message-Id: <3ecac595.30739703@news.erols.com>

lepore@brandeis.edu (bryan) wrote:

: format TABLE1 =                     
: |(x y z): @##.####,     y, @##.#### | -(x y z): @##.####,     -(y),
: @##.#### |
: $SITE_B_X_COORD_1, $SITE_B_Z_COORD_1, $SITE_B_X_COORD_1_alternate, \
: $SITE_B_Z_COORD_1_alternate;
: 
: etc...

[snip]

: and there are no
: $SITE_B_X_COORD_1_alternate scalars.

Now things are making sense.

Here's a generic, much simplified illustration of your code.

    @ary = ( $foo, $bar );
    for $i ( @ary ) {
        if ( $i < 0  ) {
            $i_alternate = (1+$i);
        }
        else {
            $i_alternate = (-1+$i);
        }
    }
    print $foo_alternate, $bar_alternate;

The loop is doing things with scalar values, and you're expecting
things to happen with the scalar names.  That's not how things work.
The names were divorced from the values after the array assignment.

It is possible to use the names (as strings) to create new scalars
with new names, but that's getting into use of symbolic references.
Not a recommended solution.

The simplest way to get what you want is with map().

    ($foo_alternate, $bar_alternate)
    = map { 
            $_ < 0 
            ?  1 + $_ 
            : -1 + $_ } $foo, $bar;

HTH



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

Date: Wed, 21 May 2003 01:03:24 GMT
From: Noerd <n_joeller@sharblbaziilyar.com>
Subject: Re: newbie needs help please
Message-Id: <3ECAD04B.2E6B72C0@sharblbaziilyar.com>

Tad McClellan wrote:

> Noerd <n_joeller@sharblbaziilyar.com> wrote:
> > Tad McClellan wrote:
> >> Noerd <n_joeller@sharblbaziilyar.com> wrote:
>
> >> > Here is the code I am using.
> >>
> >> I doubt that...
> >>
> >> > s/\(P\\\)/(papercover)/, // if title contains "(P)", replace with
> >>        ^^
> >>        ^^ what's that for?
>
> Apparently, it is "for" some mysql tool to eat before passing
>
>    s/\(P\)/(papercover)/
>
> to Real Perl.
>
> We were expected to already know that somehow?
>
> >> if title contains "(P\)", replace with "papercover"
> >>
> >> > ### I want the result to be: "My Life Story (hardbound)"
> >>
> >>    s/$/ (hardbound)/ unless s/\(P\)/(papercover)/;
>
> [snip quoted .sig]
>
> > As I stated in my original post, it is a *snippet* of code.
>
> It is presumed to be Perl code when it is posted to the Perl newsgroup.
>
> If it is not really Perl code, then you need to tell us, else the
> answer may contain Perl constructs that are not available in
> whatever unnamed "restricted Perl" it is that you are using.
>
> > And, it works
> > perfectly, because it interfaces with mysql. A previous portion of my code
> > adds slashes (escapes) via "quotemeta"
>
> So then the pattern that the regex engine ends up seeing is really
>
>    s/(P\)/(papercover)/
>
> like before the quotemeta() ?
>
> (that wouldn't "work" either.)
>
> We have to know which backslashes "count" if we are to correctly
> analyse what the pattern will match.
>
> > My
> > question should be answered on the premise that "my code works perfectly,
> > except a small adjustment is needed.
>
> To evaluate the behavior of a pattern match we *must* know what
> pattern the regex engine is operating on.
>
> We can be expected to understand what all of the punctuation characters
> mean when it is Perl code.
>
> We cannot be expected to understand what all of the punctuation characters
> mean when it is not Perl code. In that case, you would need to tell us
> what they mean, and mention that it is Not Really Perl in the first place.
>
> You did neither. (You've done it before, this last January for example)
>
> The pattern you posted did not match the text that you claimed
> it would match, so I pointed that out. Correcting mistakes is
> what happens here in clp.misc.
>
> > If such adjustment is needed, what
> > alteration to the existing code must happen to make the required small
> > adjustment."
>
> I provided just such an adjustment, did I not?
>
> > Okay Tad?
>
> I answered the question that was asked.
>
> Okay Noerd?
>
> You've now used up all of your coupons.
>
>    *plonk*
>
> --
>     Tad McClellan                          SGML consulting
>     tadmc@augustmail.com                   Perl programming
>     Fort Worth, Texas

 ....wait....here's one more....... riiiiiight here [magically pulls one more
out from behind your ear]
:-)
*bounces back*




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

Date: 20 May 2003 15:23:40 -0800
From: yf110@vtn1.victoria.tc.ca (Malcolm Dew-Jones)
Subject: Re: Perl: Regex help request
Message-Id: <3ecaaaec@news.victoria.tc.ca>

deepak p (deepak10000@hotmail.com) wrote:
: Dear Colleagues,

: I need to replace null values in a pipe separated data file with 0.
: There is one record per line and my env is perl 5.61 on Solaris if
: that matters.

: The first line of the data line is shown below along with what I would
: like to change it to.

: before
: Line 1|550|152|154|29|3|1|||||||

: would like it to be changed to
: Line 1|550|152|154|29|3|1|0|0|0|0|0|0|0

: I'm reading line-by-line and a snippet of code is pasted below.
: If anyone can show me how to apply the substitute command or do it any
: other way to get the desired result, I would appreciate it greatly.

: $File_In = "file.txt";

: open (FILE_IN, $File_In) or die "Can't read $File_In: $!";

: while (<FILE_IN2) {
:    chomp;
:    print "Dollar_under before is $_\n";
:    s/\|\|/\|0\|/g;

The problem is that after the two ||'s are replaced then the s///g starts
looking at the next character following the ||'s, therefore the second |
is not included in the next match when it should be.

The best re technique is to change the re so that one of the two |'s is
seen but not included.  The way to do that is to use either lookahead
`(?=pattern)' or lookbehind `(?<=pattern)' (read perldoc perlre) but ** I
haven't tested these **

	s/\|(?=\|)/|0/g;	# find first | of a ||
	s/(?<=\|)\|/0|/g;	# find second | of a ||

The other technique is to keep doing the substitution until there's no
more left to do.

	1 while s/\|\|/\|0\|/g;

:    print "Dollar_under after is $_\n";
: }



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

Date: 20 May 2003 15:51:23 -0700
From: dayjp@yahoo.com (Jday)
Subject: While loops and arrays
Message-Id: <827501f5.0305201451.2c532d9f@posting.google.com>

I am writing a script to iterate through each element of one array and
compare each element with another array to pick out the corresponding
value.  I have popluated my arrays by using while loops, as my data is
contained in comma delimited format:

while (<FILE>) {
    @data = split /,/;
}

My frustration is that I can't figure out how to keep and use the data
in the array after the while loop has ended.  For example, if I were
to do this:

while (<FILE>) {
    @data = split /,/;
    print "@data\n";
}

I get all the data in the array, whereas if I do this:

while (<FILE>) {
    @data = split /,/;
}
    print "@data\n";

I get the last row of data in the array.  How can I "transfer" the
data in the array from within the while loop so I can use that full
array in another portion of the script?  Thanks for your help!!!


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

Date: Tue, 20 May 2003 23:05:56 GMT
From: w i l l <willis_31_40@yahoo.com>
Subject: Re: While loops and arrays
Message-Id: <v1dlcvkmn3ue8kvautkq3kgfmqbfc3n9pi@4ax.com>

On 20 May 2003 15:51:23 -0700, dayjp@yahoo.com (Jday) wrote:

>I am writing a script to iterate through each element of one array and
>compare each element with another array to pick out the corresponding
>value.  I have popluated my arrays by using while loops, as my data is
>contained in comma delimited format:
>
>while (<FILE>) {
>    @data = split /,/;
>}
>
>My frustration is that I can't figure out how to keep and use the data
>in the array after the while loop has ended.  For example, if I were
>to do this:
>
>while (<FILE>) {
>    @data = split /,/;
>    print "@data\n";
>}
>
>I get all the data in the array, whereas if I do this:
>
>while (<FILE>) {
>    @data = split /,/;
>}
>    print "@data\n";
>
>I get the last row of data in the array.  How can I "transfer" the
>data in the array from within the while loop so I can use that full
>array in another portion of the script?  Thanks for your help!!!


Push the data to a new array, SOMHOW, like this.

for (<FILE>) {

push $_, @someArray;

}

w i l l


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

Date: Wed, 21 May 2003 01:37:34 +0200
From: Gunnar Hjalmarsson <noreply@gunnar.cc>
Subject: Re: While loops and arrays
Message-Id: <baeec8$sfjaq$1@ID-184292.news.dfncis.de>

Jday wrote:
> My frustration is that I can't figure out how to keep and use the data
> in the array after the while loop has ended.  For example, if I were
> to do this:
> 
> while (<FILE>) {
>     @data = split /,/;
>     print "@data\n";
> }
> 
> I get all the data in the array, whereas if I do this:
> 
> while (<FILE>) {
>     @data = split /,/;
> }
>     print "@data\n";
> 
> How can I "transfer" the
> data in the array from within the while loop so I can use that full
> array in another portion of the script?

Even if I'm not getting the whole picture, it sounds as if you 
possibly may want to create an array of arrays:

while (<FILE>) {
     push @data, [ split /,/ ];
}

That way you can access each element later without further split 
operations.

/ Gunnar

-- 
Gunnar Hjalmarsson
Email: http://www.gunnar.cc/cgi-bin/contact.pl



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

Date: Tue, 20 May 2003 23:35:06 GMT
From: Michael Budash <mbudash@sonic.net>
Subject: Re: While loops and arrays
Message-Id: <mbudash-E45AC1.16350520052003@typhoon.sonic.net>

In article <v1dlcvkmn3ue8kvautkq3kgfmqbfc3n9pi@4ax.com>,
 w i l l <willis_31_40@yahoo.com> wrote:

> On 20 May 2003 15:51:23 -0700, dayjp@yahoo.com (Jday) wrote:
> 
> >I am writing a script to iterate through each element of one array and
> >compare each element with another array to pick out the corresponding
> >value.  I have popluated my arrays by using while loops, as my data is
> >contained in comma delimited format:
> >
> >while (<FILE>) {
> >    @data = split /,/;
> >}
> >
> >My frustration is that I can't figure out how to keep and use the data
> >in the array after the while loop has ended.  For example, if I were
> >to do this:
> >
> >while (<FILE>) {
> >    @data = split /,/;
> >    print "@data\n";
> >}
> >
> >I get all the data in the array, whereas if I do this:
> >
> >while (<FILE>) {
> >    @data = split /,/;
> >}
> >    print "@data\n";
> >
> >I get the last row of data in the array.  How can I "transfer" the
> >data in the array from within the while loop so I can use that full
> >array in another portion of the script?  Thanks for your help!!!
> 
> 
> Push the data to a new array, SOMHOW, like this.
> 
> for (<FILE>) {
> 
> push $_, @someArray;

surely you mean:

  push @someArray, $_;

-- 
Michael Budash


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

Date: Tue, 20 May 2003 23:50:10 GMT
From: "Michael P. Broida" <michael.p.broida@boeing.com>
Subject: Re: While loops and arrays
Message-Id: <3ECABF32.939E4B1E@boeing.com>

w i l l wrote:
> 
> On 20 May 2003 15:51:23 -0700, dayjp@yahoo.com (Jday) wrote:
> 
> >I am writing a script to iterate through each element of one array and
> >compare each element with another array to pick out the corresponding
> >value.  I have popluated my arrays by using while loops, as my data is
> >contained in comma delimited format:
> >
> >while (<FILE>) {
> >    @data = split /,/;
> >}
> >
> >My frustration is that I can't figure out how to keep and use the data
> >in the array after the while loop has ended.  For example, if I were
> >to do this:
> >
> >while (<FILE>) {
> >    @data = split /,/;
> >    print "@data\n";
> >}
> >
> >I get all the data in the array, whereas if I do this:
> >
> >while (<FILE>) {
> >    @data = split /,/;
> >}
> >    print "@data\n";
> >
> >I get the last row of data in the array.  How can I "transfer" the
> >data in the array from within the while loop so I can use that full
> >array in another portion of the script?  Thanks for your help!!!
> 
> Push the data to a new array, SOMHOW, like this.
> 
> for (<FILE>) {
> 
> push $_, @someArray;
> 
> }

	Um, am I misreading that?  Or misunderstanding what you mean?
	"push" wants the ARRAY arg first, the LIST arg second.
	Shouldn't that example be:
		push @someArray, $_;
	??  That will push $_ onto the end of @someArray.

		Mike


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

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.  

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 5015
***************************************


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