[23473] in Perl-Users-Digest
Perl-Users Digest, Issue: 5687 Volume: 10
daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Tue Oct 21 00:10:55 2003
Date: Mon, 20 Oct 2003 21:10:11 -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 Mon, 20 Oct 2003 Volume: 10 Number: 5687
Today's topics:
Re: Odd Perl bitwise-AND & MySQL problem? (Jay Tilton)
Re: Odd Perl bitwise-AND & MySQL problem? (dohnut)
Re: Odd Perl bitwise-AND & MySQL problem? (Sam Holden)
Re: Odd Perl bitwise-AND & MySQL problem? (dohnut)
PAR and pp problem <mb@uq.net.au>
Re: PAR and pp problem <mb@uq.net.au>
Re: PAR and pp problem <kalinaubears@iinet.net.au>
regular expression question <lify@rubby.math.umd.edu>
Re: regular expression question <abigail@abigail.nl>
Re: Rookie: Constructing a large SQL INSERT statement <tore@aursand.no>
Re: some help <nospam_for_jkeen@concentric.net>
storing values from file into an array.-newbie (Go Perl)
Re: storing values from file into an array.-newbie <invalid-email@rochester.rr.com>
Re: storing values from file into an array.-newbie <tore@aursand.no>
Re: storing values from file into an array.-newbie (Tad McClellan)
Zipping a folder and displaying the completion rate <goth1938@hotmail.com>
Digest Administrivia (Last modified: 6 Apr 01) (Perl-Users-Digest Admin)
----------------------------------------------------------------------
Date: Tue, 21 Oct 2003 01:18:39 GMT
From: tiltonj@erols.com (Jay Tilton)
Subject: Re: Odd Perl bitwise-AND & MySQL problem?
Message-Id: <3f947f44.217129614@news.erols.com>
cmjensen@dohnut.org (dohnut) wrote:
: Ok, let's start here: I end up with an array that comes from a
: fetchrow_array() call to MySQL. I return the array to a function.
:
: Ok, then the function does this (roughly):
:
: sub func()
: {
: my @dat = shift;
: my $val = $dat[3] & $dat[4] & $dat[5] & 0x7fff;
: print $val;
: }
Good thing you said "roughly." That sub is pretty messed up.
: In the MySQL database, element 0 = int, 1 = varchar(32), 2 =
: varchar(255), 3 = int, 4 = int, 5 = int, 6 = int, etc..
:
: Ok, so I call the function. Let's assume $dat[3] = 57 (0x39), $dat[4]
: = 2045 (0x7fd), $dat[5] = 2047 (0x7ff).
:
: Guess what I get for output? --> "00" (I should get 57 (0x39) btw)
:
: Not just a zero "0" but _2_ zeros. So, clearly it thinks something
: stringy is there. But why? I guess that is my question.
Because the database query is returning the values as strings, even
though they might be stored in the database as integers.
: Now, if I populate @dat myself (i.e. don't get the values from MySQL
: calls) it works fine.
Then you're assigning numeric values, e.g.
@dat[ 3, 4, 5 ] = ( 57, 2045, 2047 );
Try it again with string values assigned and see what happens.
@dat[ 3, 4, 5 ] = ( '57', '2045', '2047' );
While most operators will force their arguments into the numeric or
string context that is appropriate to the operator, the bitwise
operators will change their own context to fit the arguments.
: To my knowledge only numbers are in the 3 variables and I've tested
: this. If I print the values individually, they print correctly. I
: also do a 'length' on them and I get 2, 4, and 4 respectively -- which
: is correct.
Neither print() nor length() will reveal wether the value is stored as a
string or as a number.
: How did I fix it?
:
: my $val = int($dat[3]) & int($dat[4]) & int($dat[5]) & 0x7fff;
That's a little overkill. To coerce the bitwise operators into working
in numeric context, perlop recommends using a simple 0+, e.g.
my $val = 0 + $dat[3] & $dat[4] & $dat[5];
: So apparently Perl thought there
: was something before the numbers in the variables??
Nope. Perl just thinks your numbers are strings, and your program
happens to use operaters where that distinction makes a difference.
------------------------------
Date: 20 Oct 2003 20:16:05 -0700
From: cmjensen@dohnut.org (dohnut)
Subject: Re: Odd Perl bitwise-AND & MySQL problem?
Message-Id: <c6e455b3.0310201916.58a96499@posting.google.com>
Here's some working code that I created to show the problem.
First the MySQL database dump
-------------------------------------------------------------
CREATE DATABASE /*!32312 IF NOT EXISTS*/ pbug;
USE pbug;
CREATE TABLE hosts (
id int(11) NOT NULL auto_increment,
ip int(4) unsigned default NULL,
password varchar(32) default NULL,
description varchar(255) default '',
clone int(4) unsigned default '0',
conn int(4) unsigned default '0',
status int(4) unsigned default '0',
tdate timestamp(14) NOT NULL,
alarms int(11) unsigned default '0',
monitored int(11) unsigned default '0',
installed int(11) unsigned default '0',
soft_ver_major int(4) default '0',
soft_ver_minor int(4) default '0',
soft_ver_incr int(4) default '0',
hard_ver_major int(4) default '0',
hard_ver_minor int(4) default '0',
hard_ver_incr int(4) default '0',
case_temp int(4) default '-1',
cpu1_temp int(4) default '-1',
cpu2_temp int(4) default '-1',
ext_temp int(4) default '-1',
PRIMARY KEY (id),
UNIQUE KEY ip (ip)
) TYPE=MyISAM;
INSERT INTO hosts VALUES (1,168430090,'crystal','Demo
XXXXXXXX',0,129,0,20031020210116,0,61,7,0,0,0,0,0,0,29,-1,-1,-1);
INSERT INTO hosts VALUES (2,185273099,'password','Test XXXXXXXX
#1\r\n',0,129,0,20031020210117,57,2045,2047,0,0,0,0,0,0,31,-1,-1,-1);
INSERT INTO hosts VALUES (3,202116108,'password','Another
XXXXXXXX\r\n\r\n',0,129,0,20031020210118,3,7,63,0,0,0,0,0,0,30,-1,-1,-1);
--------------------------------------------
Put this into a file and add it to your mysql server.
type: mysql -u <username> -p<password> < pbug.sql
Ok, and here's my little perl module that demonstrates the error (or
my stupidity).
------------------------------------------------
#!/usr/bin/perl -w
use strict;
use warnings;
use DBI;
foreach (1..3)
{
my @dat = &GetHostStatus( $_ );
print "$_: ";
#printf "0x%x & 0x%x & 0x%x & 0x7fff = ", $dat[3], $dat[4],
$dat[5];
print $dat[3] & $dat[4] & $dat[5] & 0x7fff;
print "\n";
}
1;
########################################################################
sub GetHostStatus()
{
my $id = shift || return ();
my $db = DBI->connect( 'dbi:mysql:pbug','bla','bla' ) || die(
DBI->errstr );
my $query = "SELECT ip, password, description, alarms, monitored,
installed, case_temp, cpu1_temp, cpu2_temp, ext_temp FROM hosts WHERE
id = $id";
my $sth = $db->prepare( $query ) || die( DBI->errstr );
$sth->execute() || die( DBI->errstr );
my @row = $sth->fetchrow_array();
$sth->finish;
$db->disconnect;
return @row;
}
--------------------------------------------------
When I run this on my system, here is my output:
1: 0
2: 0
3: 2
Clearly incorrect. Now, when I uncomment that printf line:
1: 0x0 & 0x3d & 0x7 & 0x7fff = 0
2: 0x39 & 0x7fd & 0x7ff & 0x7fff = 57
3: 0x3 & 0x7 & 0x3f & 0x7fff = 3
Then it works.. Hmm...
I've tested this on 2 separate systems now with the same results, I'd
be interested to see if any of you guys can duplicate it also? Or
tell me where I screwed up, that would be better (and more likely).
Regardless, I'd appreciate any feedback.
- Chris
------------------------------
Date: 21 Oct 2003 03:46:18 GMT
From: sholden@flexal.cs.usyd.edu.au (Sam Holden)
Subject: Re: Odd Perl bitwise-AND & MySQL problem?
Message-Id: <slrnbp9b09.rm4.sholden@flexal.cs.usyd.edu.au>
On 20 Oct 2003 20:16:05 -0700, dohnut <cmjensen@dohnut.org> wrote:
> Here's some working code that I created to show the problem.
>
> First the MySQL database dump
[snip the dump]
> ------------------------------------------------
> #!/usr/bin/perl -w
>
> use strict;
> use warnings;
> use DBI;
>
>
> foreach (1..3)
> {
> my @dat = &GetHostStatus( $_ );
Why are you using the & there?
>
> print "$_: ";
> #printf "0x%x & 0x%x & 0x%x & 0x7fff = ", $dat[3], $dat[4],
> $dat[5];
> print $dat[3] & $dat[4] & $dat[5] & 0x7fff;
> print "\n";
> }
[snip the GetHostStatus code]
> --------------------------------------------------
>
> When I run this on my system, here is my output:
>
> 1: 0
> 2: 0
> 3: 2
>
> Clearly incorrect. Now, when I uncomment that printf line:
>
> 1: 0x0 & 0x3d & 0x7 & 0x7fff = 0
> 2: 0x39 & 0x7fd & 0x7ff & 0x7fff = 57
> 3: 0x3 & 0x7 & 0x3f & 0x7fff = 3
>
> Then it works.. Hmm...
The values are strings. Perl defines a bitwise & operator for
strings and hence uses it. Doing the printf causes perl to generate
a numeric version of the value, so then the & operator operates
on the numbers.
The database stuff is all irrelevant (aside from the fact it is returning
strings):
# start with numbers
my ($x,$y,$z) = (0x39,0x7fd,0x77f);
print $x & $y & $z & 0x7fff, "\n";
# create string variables containing the numbers as strings.
my ($sx, $sy, $sz) = ("$x", "$y", "$z");
print $sx & $sy & $sz & 0x7fff, "\n";
# create numeric 'version's of the strings...
# adding 0 seems clearer than the printf side effect :)
$_ += 0 for ($sx, $sy, $sz);
print $sx & $sy & $sz & 0x7fff, "\n";
Things like this is why the knowledgable people here always argue against
posters who quote variables for no reason (replace the '("$x", "$y", "$z")'
in that code with '($z, $y, $z)' and the bahaviour will change).
--
Sam Holden
------------------------------
Date: 20 Oct 2003 20:55:06 -0700
From: cmjensen@dohnut.org (dohnut)
Subject: Re: Odd Perl bitwise-AND & MySQL problem?
Message-Id: <c6e455b3.0310201955.39df5af3@posting.google.com>
> While most operators will force their arguments into the numeric or
> string context that is appropriate to the operator, the bitwise
> operators will change their own context to fit the arguments.
Ahh, you know I don't think I knew that. Funny this hasn't affected
me earlier, though I guess I don't do a lot of bit operations on data
from databases.
I guess it was just drilled into my head that perl doesn't have data
types, so the thought never crossed my mind that it would care that
the data is actually a string and not an integer. And it doesn't --
except for bit operations. :P
Well, thanks, that saved me a lot of fruitless debugging. Obviously
my follow-up I just made can be disregarded, though, at least the code
actually 'works' in that one (or doesn't, depending on how you look at
it). ;)
-Chris
------------------------------
Date: Tue, 21 Oct 2003 11:41:43 +1000
From: Matthew Braid <mb@uq.net.au>
Subject: PAR and pp problem
Message-Id: <bn22sm$gei$1@bunyip.cc.uq.edu.au>
Hi all,
I just installed the PAR-0.75 package from CPAN and while all tests
passed OK I'm having a few problems.
It seems the 'parl' script that gets installed with it is munged. When I
run the following:
mdb:~/temp> pp -e 'print "HELLO!\n"' -o hello
I get:
/usr/local/bin/parl: FILE837fb41f/PAR.pmH#line: not found
/usr/local/bin/parl: 80: Syntax error: ";" unexpected
I checked the parl script and the first two lines were some kind of
garbage. I removed them and added '#!/usr/local/bin/perl' and now I get:
Unrecognized character \x15 at /usr/local/bin/parl line 436.
Line 436 is in the middle of a comment.
I've reinstalled just in case and the same thing happened. Anyone see
this before or know how to fix it? I'll try the previous version if this
one is bad.
TIA,
MB
------------------------------
Date: Tue, 21 Oct 2003 13:41:02 +1000
From: Matthew Braid <mb@uq.net.au>
Subject: Re: PAR and pp problem
Message-Id: <bn29sd$auh$1@bunyip.cc.uq.edu.au>
Just a little more info...
I just tried the previous version (0.74) and got the same problem.
I looked further into the parl script and found more lines that had
garbage like:
FILE^@^@^U4c1372fb/PAR/Heavy.pm^@^@N2#line 1 "../blib/lib/PAR/Heavy.pm"
(or something similar - the file names change)
Commenting out these lines results in:
Global symbol "%DLCache" requires explicit package name at
/usr/local/bin/parl line 43.
Global symbol "%DLCache" requires explicit package name at
/usr/local/bin/parl line 43.
Global symbol "%DLCache" requires explicit package name at
/usr/local/bin/parl line 70.
Global symbol "%DLCache" requires explicit package name at
/usr/local/bin/parl line 74.
Global symbol "%DLCache" requires explicit package name at
/usr/local/bin/parl line 85.
Global symbol "%FullCache" requires explicit package name at
/usr/local/bin/parl line 94.
Global symbol "%DLCache" requires explicit package name at
/usr/local/bin/parl line 95.
Global symbol "%FullCache" requires explicit package name at
/usr/local/bin/parl line 95.
BEGIN not safe after errors--compilation aborted at /usr/local/bin/parl
line 175
In case its important, perl -V gives:
Summary of my perl5 (revision 5.0 version 8 subversion 1) configuration:
Platform:
osname=freebsd, osvers=4.8-release, archname=i386-freebsd-64int
uname='freebsd app 4.8-release freebsd 4.8-release #1: thu may 1
12:03:49 est 2003 root@app:usrobjusrsrcsysapp i386 '
config_args='-Accflags=-DAPPLLIB_EXP=\"/usr/local/lib/perl-local\"'
hint=recommended, useposix=true, d_sigaction=define
usethreads=undef use5005threads=undef useithreads=undef
usemultiplicity=undef
useperlio=define d_sfio=undef uselargefiles=define usesocks=undef
use64bitint=define use64bitall=undef uselongdouble=undef
usemymalloc=n, bincompat5005=undef
Compiler:
cc='cc', ccflags ='-DHAS_FPSETMASK -DHAS_FLOATINGPOINT_H
-DAPPLLIB_EXP="/usr/local/lib/perl-local" -fno-strict-aliasing
-I/usr/local/include',
optimize='-O',
cppflags='-DHAS_FPSETMASK -DHAS_FLOATINGPOINT_H
-DAPPLLIB_EXP="/usr/local/lib/perl-local" -fno-strict-aliasing
-I/usr/local/include'
ccversion='', gccversion='2.95.4 20020320 [FreeBSD]', gccosandvers=''
intsize=4, longsize=4, ptrsize=4, doublesize=8, byteorder=12345678
d_longlong=define, longlongsize=8, d_longdbl=define, longdblsize=12
ivtype='long long', ivsize=8, nvtype='double', nvsize=8,
Off_t='off_t', lseeksize=8
alignbytes=4, prototype=define
Linker and Libraries:
ld='cc', ldflags ='-Wl,-E -L/usr/local/lib'
libpth=/usr/lib /usr/local/lib
libs=-lm -lcrypt -lutil -lc
perllibs=-lm -lcrypt -lutil -lc
libc=, so=so, useshrplib=false, libperl=libperl.a
gnulibc_version=''
Dynamic Linking:
dlsrc=dl_dlopen.xs, dlext=so, d_dlsymun=undef, ccdlflags=' '
cccdlflags='-DPIC -fPIC', lddlflags='-shared -L/usr/local/lib'
Characteristics of this binary (from libperl):
Compile-time options: USE_64_BIT_INT USE_LARGE_FILES
Built under freebsd
Compiled at Oct 15 2003 16:59:35
@INC:
/usr/local/lib/perl-local
/usr/local/lib/perl5/5.8.1/i386-freebsd-64int
/usr/local/lib/perl5/5.8.1
/usr/local/lib/perl5/site_perl/5.8.1/i386-freebsd-64int
/usr/local/lib/perl5/site_perl/5.8.1
/usr/local/lib/perl5/site_perl
.
MB
Matthew Braid wrote:
> Hi all,
>
> I just installed the PAR-0.75 package from CPAN and while all tests
> passed OK I'm having a few problems.
>
> It seems the 'parl' script that gets installed with it is munged. When I
> run the following:
>
> mdb:~/temp> pp -e 'print "HELLO!\n"' -o hello
>
> I get:
>
> /usr/local/bin/parl: FILE837fb41f/PAR.pmH#line: not found
> /usr/local/bin/parl: 80: Syntax error: ";" unexpected
>
> I checked the parl script and the first two lines were some kind of
> garbage. I removed them and added '#!/usr/local/bin/perl' and now I get:
>
> Unrecognized character \x15 at /usr/local/bin/parl line 436.
>
> Line 436 is in the middle of a comment.
>
> I've reinstalled just in case and the same thing happened. Anyone see
> this before or know how to fix it? I'll try the previous version if this
> one is bad.
>
> TIA,
> MB
>
------------------------------
Date: Tue, 21 Oct 2003 13:55:57 +1000
From: Sisyphus <kalinaubears@iinet.net.au>
Subject: Re: PAR and pp problem
Message-Id: <3f94af06$0$23596$5a62ac22@freenews.iinet.net.au>
Matthew Braid wrote:
> Just a little more info...
>
> I just tried the previous version (0.74) and got the same problem.
[snip]
>
> In case its important, perl -V gives:
>
> Summary of my perl5 (revision 5.0 version 8 subversion 1) configuration:
> Platform:
> osname=freebsd, osvers=4.8-release, archname=i386-freebsd-64int
> uname='freebsd app 4.8-release freebsd 4.8-release #1: thu may 1
Might be a freebsd-specific issue.
Best, imho, to post par questions to the par mailing list (see
http://lists.perl.org) - where you're sure to grab the attention of the
author. (I'm not saying that you definitely won't get quality help here,
however :-)
Cheers,
Rob
--
To reply by email u have to take out the u in kalinaubears.
------------------------------
Date: Mon, 20 Oct 2003 23:31:09 +0000 (UTC)
From: <lify@rubby.math.umd.edu>
Subject: regular expression question
Message-Id: <bn1r7t$neg$2@grapevine.wam.umd.edu>
in the following regular express
$_="BCADeFGHIJKL";
if (/\L[\w]\E/) { print "true"} else { print "false\n" };
if (/\U[\w]\E/) { print "true"} else { print "false\n" };
why the first one print true while the second one print false?
Can someone explain \L \U?
------------------------------
Date: 20 Oct 2003 23:45:49 GMT
From: Abigail <abigail@abigail.nl>
Subject: Re: regular expression question
Message-Id: <slrnbp8std.pik.abigail@alexandra.abigail.nl>
<lify@rubby.math.umd.edu> (lify@rubby.math.umd.edu) wrote on MMMDCCII
September MCMXCIII in <URL:news:bn1r7t$neg$2@grapevine.wam.umd.edu>:
:: in the following regular express
:: $_="BCADeFGHIJKL";
:: if (/\L[\w]\E/) { print "true"} else { print "false\n" };
:: if (/\U[\w]\E/) { print "true"} else { print "false\n" };
::
:: why the first one print true while the second one print false?
:: Can someone explain \L \U?
\L means: lowercase what follows, until the end of the string, or \E,
whatever comes first.
\U means: lowercase what follows, until the end of the string, or \E,
whatever comes first.
This is done *before* the regex is compiled. So, /\L[\w]\E/ is just
the same as /[\w]/, but /\U[\w]\E/ equals /[\W]/. The latter means
"match if there is a non-word character present"; since there is none,
it returns false.
Abigail
--
$_ = "\x3C\x3C\x45\x4F\x54";
print if s/<<EOT/<<EOT/e;
Just another Perl Hacker
EOT
------------------------------
Date: Tue, 21 Oct 2003 00:54:44 +0200
From: Tore Aursand <tore@aursand.no>
Subject: Re: Rookie: Constructing a large SQL INSERT statement
Message-Id: <pan.2003.10.20.17.39.05.360269@aursand.no>
On Mon, 20 Oct 2003 09:43:53 -0700, nobull wrote:
>> $stInsert->finish();
> Unnecessarly calling finish() on DBI statement handles is, IMHO, a bad
> habit.
Really? Hmm. I started using DBI about 5 years ago, and I remember
having a problem with "something" which didn't go away until I added the
call to those finish() methods.
Anyway. Why is it bad? I still go for the "slow, but safe" approach when
programing, and find myself constantly doing prepare(), execute() and
finish() even when a do() would have been enough.
Oh, well. :-)
--
Tore Aursand <tore@aursand.no>
------------------------------
Date: 20 Oct 2003 23:52:55 GMT
From: "James E Keenan" <nospam_for_jkeen@concentric.net>
Subject: Re: some help
Message-Id: <bn1sgn$39r@dispatch.concentric.net>
"Hernan" <harteta@teleandina.net> wrote in message
news:895432a7.0310201325.5f2c7b34@posting.google.com...
[snip]
> This formats repeat in every call, my problem comes when I try to fit
> all this 3 lines in one line (I can parse 1 string), the data in line
> 2 and 3 starts after "&".
Please explain the problem better. In data sample you submitted, there's
nothing after the '&'.
------------------------------
Date: 20 Oct 2003 15:51:02 -0700
From: puissant00@yahoo.com (Go Perl)
Subject: storing values from file into an array.-newbie
Message-Id: <d3825316.0310201451.68fa9e7a@posting.google.com>
I am having difficulties accessing these values outside this while
loop. I am able to get only the last elements of the array outside.
what should i do to store each of these elements c_array[1],...in an
array and how to access them later ?
while ($c_line=<CONTROL_FILE>) {
chop($c_line);
@c_array = split(/\t/, $c_line);
if ($c_array[4] != "flag" && $c_array[4] == 1) {
$bit_length = blength($c_array[3],$c_array[2]);
$number_Par = $number_Par + 1;
$BIT = $BIT + $bit_length;
printf OUT_CONTROL ("%d\t%d\t%d\t%d\n", $c_array[1], $c_array[2],
$c_array[3], $bit_length);
}
}
------------------------------
Date: Mon, 20 Oct 2003 23:19:37 GMT
From: Bob Walton <invalid-email@rochester.rr.com>
Subject: Re: storing values from file into an array.-newbie
Message-Id: <3F946CBD.7020905@rochester.rr.com>
Go Perl wrote:
> I am having difficulties accessing these values outside this while
> loop. I am able to get only the last elements of the array outside.
> what should i do to store each of these elements c_array[1],...in an
> array and how to access them later ?
>
> while ($c_line=<CONTROL_FILE>) {
> chop($c_line);
> @c_array = split(/\t/, $c_line);
> if ($c_array[4] != "flag" && $c_array[4] == 1) {
> $bit_length = blength($c_array[3],$c_array[2]);
> $number_Par = $number_Par + 1;
> $BIT = $BIT + $bit_length;
> printf OUT_CONTROL ("%d\t%d\t%d\t%d\n", $c_array[1], $c_array[2],
> $c_array[3], $bit_length);
>
> }
>
> }
>
Well, every time through the loop you are reassigning @c_array, so of
course only the last line's worth is in it when you are done. If you
want to save that array in another array, add something like:
push @output_array,[@c_array];
in the vicinity of your printf statement.
And BTW, you have an improper use of a relational operator.
use warnings;
would have told you that. Always always always use warnings; and use
strict; during development! Something like:
use warnings;
use strict;
my $c_line;
my @c_array;
my $bit_length;
my $number_Par;
my $BIT;
my @output_array;
while ($c_line=<DATA>) {
chop($c_line);
@c_array = split(/\t/, $c_line);
if ($c_array[4] != "flag" && $c_array[4] == 1) {
$bit_length = blength($c_array[3],$c_array[2]);
$number_Par = $number_Par + 1;
$BIT = $BIT + $bit_length;
printf ("%d\t%d\t%d\t%d\n", $c_array[1], $c_array[2],
$c_array[3], $bit_length);
push @output_array,[@c_array];
}
}
use Data::Dumper;
print Dumper(\@output_array);
sub blength{
return 42; #or something
}
__END__
9
2
3
2
1
1
2
3
4
1
3
4
5
6
1
--
Bob Walton
Email: http://bwalton.com/cgi-bin/emailbob.pl
------------------------------
Date: Tue, 21 Oct 2003 01:34:12 +0200
From: Tore Aursand <tore@aursand.no>
Subject: Re: storing values from file into an array.-newbie
Message-Id: <pan.2003.10.20.23.03.19.17362@aursand.no>
On Mon, 20 Oct 2003 15:51:02 -0700, Go Perl wrote:
> I am having difficulties accessing these values outside this while
> loop.
Have you tried declaring '@c_value' outside the loop?
--
Tore Aursand <tore@aursand.no>
------------------------------
Date: Mon, 20 Oct 2003 18:59:19 -0500
From: tadmc@augustmail.com (Tad McClellan)
Subject: Re: storing values from file into an array.-newbie
Message-Id: <slrnbp8tmn.kps.tadmc@magna.augustmail.com>
Go Perl <puissant00@yahoo.com> wrote:
> I am having difficulties accessing these values outside this while
> loop. I am able to get only the last elements of the array outside.
That's because you overwrite the old values each time through
the loop.
> what should i do to store each of these elements c_array[1],...in an
> array and how to access them later ?
Don't overwrite the old values each time through the loop. :-)
> while ($c_line=<CONTROL_FILE>) {
> chop($c_line);
That's how it was done over 7 years ago.
Where are you learning your Perl from?
chomp($c_line);
> @c_array = split(/\t/, $c_line);
Assignment overwrites whatever used to be there.
You haven't said what exactly you want in @c_array.
If you want _all_ of the values in @c_array:
push @c_array, split(/\t/, $c_line);
If you want a LoL in @c_array:
push @c_array, [ split(/\t/, $c_line) ];
> if ($c_array[4] != "flag" && $c_array[4] == 1) {
^^
^^
You should always enable warnings when developing Perl code!
You are using the wrong operator there.
> $number_Par = $number_Par + 1;
$number_Par++;
--
Tad McClellan SGML consulting
tadmc@augustmail.com Perl programming
Fort Worth, Texas
------------------------------
Date: Tue, 21 Oct 2003 06:55:46 +0800
From: "Just in" <goth1938@hotmail.com>
Subject: Zipping a folder and displaying the completion rate
Message-Id: <bn1p5j$ml4$1@news01.intel.com>
I'm using Archive::Zip and Archive::Zip::Tree to zip a hefty folder, and its
sub folders. What I'd like to do is display how much has been done.
Since perl executes line by line I was wondering how to display the
percentage completed. I mean nothing is going to execute until these lines
get done:
die "Write error to $ZipFile" if $Zip->addTree($ServerDir) != AZ_OK;
$Zip->writeToFileNamed($ZipFile);
Threads and forks sounded like trees to bark at, but googling hasn't
provided any help as to whether I should or shouldn't. Plus I got put off
with my AS 5.6 and the ithreads argument.
Any pointers appreciated.
Thanks
Just in
------------------------------
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 5687
***************************************