[24452] in Perl-Users-Digest
Perl-Users Digest, Issue: 6635 Volume: 10
daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Mon May 31 18:10:39 2004
Date: Mon, 31 May 2004 15: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, 31 May 2004 Volume: 10 Number: 6635
Today's topics:
Re: reading variable and fixed length records <nothingread@hotmail.com>
Re: reading variable and fixed length records <noreply@gunnar.cc>
Re: reading variable and fixed length records <uri@stemsystems.com>
Re: reading variable and fixed length records <gnari@simnet.is>
Re: reading variable and fixed length records (Anno Siegel)
Re: reading variable and fixed length records <tassilo.parseval@rwth-aachen.de>
Re: Removing HTML tags: is there a Perl-equivalent to P <noreply@gunnar.cc>
split problem (Michael O'Connor)
Re: split problem (Anno Siegel)
Re: split problem <gnari@simnet.is>
Re: splitting cvs file and insert in mysql via DBI <javier@t-online.de>
Re: splitting cvs file and insert in mysql via DBI <javier@t-online.de>
Re: splitting cvs file and insert in mysql via DBI <usenet@morrow.me.uk>
Re: splitting cvs file and insert in mysql via DBI <1usa@llenroc.ude>
Re: splitting cvs file and insert in mysql via DBI <gnari@simnet.is>
Re: splitting cvs file and insert in mysql via DBI <gnari@simnet.is>
Re: strange behavior <perl@my-header.org>
Re: strange behavior <perl@my-header.org>
Re: strange behavior <usenet@morrow.me.uk>
Re: Using Cookies With Perl (krakle)
Re: Why is this upload script not working (Mark Constant)
Re: Why is this upload script not working (krakle)
Re: Why is this upload script not working <spamtrap@dot-app.org>
Digest Administrivia (Last modified: 6 Apr 01) (Perl-Users-Digest Admin)
----------------------------------------------------------------------
Date: Mon, 31 May 2004 19:15:53 +0100
From: bof <nothingread@hotmail.com>
Subject: Re: reading variable and fixed length records
Message-Id: <glH0jlLZZ3uAFwcn@invalid.domain>
In message <2i19p0Fhos6rU1@uni-berlin.de>, Gunnar Hjalmarsson
<noreply@gunnar.cc> writes
>bof wrote:
>> I'm trying to read a file with records of the form:
>> [byteA][byteB]...[byteN][0][byte1][byte2][byte3]
>> i.e. an initial variable length part; a zero marker; then a fixed
>> number of bytes; with no delimiter between the records.
>> Any pointers for a Perl noob on how to achieve this ?
>
>Achieve what? Your description is not very clear.
Apologies, it's not what you read it to be . . .
In terms of byte values the file might contain:
Hex: 41,42,43,00,FF,00,80,5A,59,58,57,56,55,54,00,00,80,FF
val: |---vv---|mm|---ff---|---------VV---------|MM|---FF---|
rec: |-------record 1-----|-----------RECORD 2-------------|
where:
Hex: is the hex data
val: "vv/VV" variable length data, "mm/MM" end of variable length
marker, "ff/FF" fixed length data; lower/upper case differentiating two
adjacent records.
--
bof at bof dot me dot uk
------------------------------
Date: Mon, 31 May 2004 20:37:22 +0200
From: Gunnar Hjalmarsson <noreply@gunnar.cc>
Subject: Re: reading variable and fixed length records
Message-Id: <2i1cmcFhp1kuU1@uni-berlin.de>
bof wrote:
> Gunnar Hjalmarsson writes:
>> bof wrote:
>>> Any pointers for a Perl noob on how to achieve this ?
>>
>> Achieve what? Your description is not very clear.
>
> Apologies, it's not what you read it to be . . .
No problem, it gave me an opportunity to figure out how to apply the
unpack() function to my self-invented problem. :)
Think your problem is above my head, so I'll leave it to those, to
whom your clarification makes sense, to help...
--
Gunnar Hjalmarsson
Email: http://www.gunnar.cc/cgi-bin/contact.pl
------------------------------
Date: Mon, 31 May 2004 18:52:52 GMT
From: Uri Guttman <uri@stemsystems.com>
Subject: Re: reading variable and fixed length records
Message-Id: <x7r7t077jw.fsf@mail.sysarch.com>
>>>>> "b" == bof <nothingread@hotmail.com> writes:
>> Achieve what? Your description is not very clear.
b> Apologies, it's not what you read it to be . . .
b> In terms of byte values the file might contain:
b> Hex: 41,42,43,00,FF,00,80,5A,59,58,57,56,55,54,00,00,80,FF val:
b> |---vv---|mm|---ff---|---------VV---------|MM|---FF---| rec:
b> |-------record 1-----|-----------RECORD 2-------------|
b> where:
b> Hex: is the hex data
b> val: "vv/VV" variable length data, "mm/MM" end of variable length
b> marker, "ff/FF" fixed length data; lower/upper case differentiating
b> two adjacent records.
when using wacko formats like this (or any file format, really) you must
provide a proper spec like this. your first post was sorta clear to me
but this is much better.
now munging with $/ on the fly is not something i would like to
see. that idea would work but just makes me feel nasty. i have done
similar stuff and it is better to just read in blocks of data and scan
for records yourself. here is very untested code:
while( 1 ) {
# read in another block, appending it to $buffer
my $read_cnt =
sysread( $fh, $buffer, 4096, length $buffer ) ;
unless ( $read_cnt ) {
print "done?\n" ;
exit ;
}
# we process all records found in this data block
while( 1 ) {
# grab and delete any leading record
# if we don't find it we need to read in more so exit
# /s is so . could match a \012 which is in the fixed part of the record
last unless $buffer =~ s/^([\0]+)\0(.{3})//s ;
process_record( $1, $2 ) ;
}
}
uri
--
Uri Guttman ------ uri@stemsystems.com -------- http://www.stemsystems.com
--Perl Consulting, Stem Development, Systems Architecture, Design and Coding-
Search or Offer Perl Jobs ---------------------------- http://jobs.perl.org
------------------------------
Date: Mon, 31 May 2004 19:06:10 -0000
From: "gnari" <gnari@simnet.is>
Subject: Re: reading variable and fixed length records
Message-Id: <c9fvjs$pv3$1@news.simnet.is>
"bof" <nothingread@hotmail.com> wrote in message
news:QUDovIKKy2uAFwp3@invalid.domain...
> In message <c9fnld$k13$1@canopus.cc.umanitoba.ca>, Walter Roberson
> <roberson@ibd.nrc-cnrc.gc.ca> writes
> >In article <JkVuDBHR51uAFw5X@invalid.domain>,
> >bof <nothingread@hotmail.com> wrote:
> >:I'm trying to read a file with records of the form:
> >
> >:[byteA][byteB]...[byteN][0][byte1][byte2][byte3]
> >
> >:i.e. an initial variable length part; a zero marker; then a fixed number
> >:of bytes; with no delimiter between the records.
> >
> >You could set $/ to 0 and do a <>, which would get you the part up to
> >the 0. Then set $/ to an integer which is the size of the fixed part
> >of the record, and do another <> to get the fixed part.
> >
> >(Setting $/ to an integer was not supported until roughly perl 5.6.)
>
> Thanks, I'll give it a go. I'd got as far as the $/ to 0 bit, but hadn't
> seen any reference to setting an integer value; though this does beg the
> question how to differentiate between requesting 13 characters and using
> "\n" as the delimiter, I guess this is through the type of the value $/
> is set to?
well actually, the question you should ask is how to differentiate
between requesting 13 chars and using "13" as the delimiter. the answer,
of course is that Walter was not entirely correct. to specify a fixed length
record, use a *reference* to an integer.
$/=\13; # 13 byte records
$/=13; # "13" is endofline
$/="13"; # ditto
$/="\015";# CR is end of line (byte 13)
$/="\r" ;# CR is end of line (byte 13 on some operating systems)
gnari
------------------------------
Date: 31 May 2004 20:09:59 GMT
From: anno4000@lublin.zrz.tu-berlin.de (Anno Siegel)
Subject: Re: reading variable and fixed length records
Message-Id: <c9g3en$qr0$1@mamenchi.zrz.TU-Berlin.DE>
Uri Guttman <uri@stemsystems.com> wrote in comp.lang.perl.misc:
> >>>>> "b" == bof <nothingread@hotmail.com> writes:
>
> >> Achieve what? Your description is not very clear.
>
> b> Apologies, it's not what you read it to be . . .
>
>
> b> In terms of byte values the file might contain:
>
> b> Hex: 41,42,43,00,FF,00,80,5A,59,58,57,56,55,54,00,00,80,FF val:
> b> |---vv---|mm|---ff---|---------VV---------|MM|---FF---| rec:
> b> |-------record 1-----|-----------RECORD 2-------------|
>
> b> where:
>
> b> Hex: is the hex data
>
> b> val: "vv/VV" variable length data, "mm/MM" end of variable length
> b> marker, "ff/FF" fixed length data; lower/upper case differentiating
> b> two adjacent records.
>
> when using wacko formats like this (or any file format, really) you must
> provide a proper spec like this. your first post was sorta clear to me
> but this is much better.
>
> now munging with $/ on the fly is not something i would like to
> see. that idea would work but just makes me feel nasty. i have done
> similar stuff and it is better to just read in blocks of data and scan
> for records yourself. here is very untested code:
[code snipped]
The price is that you have to do your own input-buffering.
Alternatively set $/ = "\0" for good. Then each chunk read
from the file contains the fixed part of the last record and the
variable part of the next one, except for the first chunk. Taking
this into account in the loop isn't too hard:
$/ = "\0";
my ( $var_part, $fixed_part);
while ( <$f> ) {
chomp;
unless ( $. == 1 ) {
$fixed_part = substr( $_, 0, 2, ''); # extract and delete
print "fix: $fixed_part, var: $var_part\n";
}
$var_part = $_; # ...of next record
}
There is no special treatment of the last record, which one might expect.
Perl's IO and chomp() deal with it in the final round of the loop.
Anno
------------------------------
Date: Mon, 31 May 2004 22:29:11 +0200
From: "Tassilo v. Parseval" <tassilo.parseval@rwth-aachen.de>
Subject: Re: reading variable and fixed length records
Message-Id: <2i1isqFf1j4pU1@uni-berlin.de>
Also sprach bof:
> I'm trying to read a file with records of the form:
>
> [byteA][byteB]...[byteN][0][byte1][byte2][byte3]
>
> i.e. an initial variable length part; a zero marker; then a fixed number
> of bytes; with no delimiter between the records.
>
> Any pointers for a Perl noob on how to achieve this ?
Use unpack(). For the initial variable part, the 'Z' template looks
right. As for the final four bytes, that would depend on what they
represent. When they are integer, use 'V' for little-endian and 'N' for
big-endian format. In code this would read:
my ($initial, $final) = unpack "ZN", $record;
If these four bytes are just ordinary bytes then use 'Za4'.
But maybe you get away without using unpack() at all. The problem with
your records is that they have no fixed length. So maybe adjusting the
input record separator accordingly is easier [untested]:
$/ = "\0";
my @records;
while (<FILE>) {
chomp;
# next is the four bytes
$/ = \4;
push @records, [ $_, scalar <FILE> ];
# after which a NULL-padded has to be read
$/ = "\0";
}
This will put all records broken into its variable length part and the
four bytes into @records.
Tassilo
--
$_=q#",}])!JAPH!qq(tsuJ[{@"tnirp}3..0}_$;//::niam/s~=)]3[))_$-3(rellac(=_$({
pam{rekcahbus})(rekcah{lrePbus})(lreP{rehtonabus})!JAPH!qq(rehtona{tsuJbus#;
$_=reverse,s+(?<=sub).+q#q!'"qq.\t$&."'!#+sexisexiixesixeseg;y~\n~~dddd;eval
------------------------------
Date: Mon, 31 May 2004 20:05:04 +0200
From: Gunnar Hjalmarsson <noreply@gunnar.cc>
Subject: Re: Removing HTML tags: is there a Perl-equivalent to PHP 'strip_tags'?
Message-Id: <2i1appFhct2rU1@uni-berlin.de>
Bill wrote:
> Francesco Moi wrote:
>> I've got some HTML texts, but I want to remove HTML tags from it.
>> I mean, convert '<b>foo</b>' into 'foo'.
>>
>> In PHP you can use 'strip_tags':
>> http://www.php.net/strip_tags
>>
>> Is there any Perl-equivalent?
>
> Why not google for it first?
>
> http://groups.google.com/groups?q=perl+strip_tags&hl=en&lr=&ie=UTF-8&selm=92d64088.0309241735.7a05269c%40posting.google.com&rnum=3
Or check out the Perl FAQ:
perldoc -q "remove HTML"
--
Gunnar Hjalmarsson
Email: http://www.gunnar.cc/cgi-bin/contact.pl
------------------------------
Date: 31 May 2004 12:41:11 -0700
From: moconnor59@yahoo.com (Michael O'Connor)
Subject: split problem
Message-Id: <fc3110e8.0405311141.6b446cb2@posting.google.com>
I have a string containing pipe-delimited fields, but the string can
contain binary data which may itself include pipe characters - in
which case the pipe is escaped with a backslash. Backslash characters
are also escaped in the string (with another backslash) to distinguish
them from other escaped characters.
I'm trying to split this string into its constituent fields. Based on
the above, the delimiter is defined as a pipe-character that is not
preceeded by an odd number of backslash characters (i.e. it's
preceeded by zero or an even number of backslash characters).
As perl doesn't support variable length look-behind, I'm reversing the
string and using look-ahead instead. The nearest I've got this to
working is:
my $escape = '\\';
my $separator = '|';
my @fields = split(/\Q$separator\E(?=(\Q$escape$escape\E)*[^\Q$escape\E])/,
reverse $value);
At this point I'm expecting @fields to be a reversed list of
individually reversed fields, but I'm finding it contains extra fields
(either empty or containing 2 escape characters).
E.g. when trying to split string 'A|B\|C|D\\|E' (reverse =
'E|\\D|C|\B|A'), I'm hoping to get @fields = ('E', '\\D', 'C|\B',
'A'), but instead I get ('E', '\\', '\\D', '', 'C|\B', '', 'A').
Can anyone tell me how I avoid getting these extra fields in the
result?
Thanks,
Michael
------------------------------
Date: 31 May 2004 20:19:52 GMT
From: anno4000@lublin.zrz.tu-berlin.de (Anno Siegel)
Subject: Re: split problem
Message-Id: <c9g418$qr0$2@mamenchi.zrz.TU-Berlin.DE>
Michael O'Connor <moconnor59@yahoo.com> wrote in comp.lang.perl.misc:
> I have a string containing pipe-delimited fields, but the string can
> contain binary data which may itself include pipe characters - in
> which case the pipe is escaped with a backslash. Backslash characters
> are also escaped in the string (with another backslash) to distinguish
> them from other escaped characters.
[...]
That's a FAQ:
How can I split a [character] delimited string except when inside
[character]?
The answer points (mostly) to a number of modules that handle this
type of data.
Anno
------------------------------
Date: Mon, 31 May 2004 20:25:46 -0000
From: "gnari" <gnari@simnet.is>
Subject: Re: split problem
Message-Id: <c9g493$qg2$1@news.simnet.is>
"Michael O'Connor" <moconnor59@yahoo.com> wrote in message
news:fc3110e8.0405311141.6b446cb2@posting.google.com...
> I have a string containing pipe-delimited fields, but the string can
> contain binary data which may itself include pipe characters - in
> which case the pipe is escaped with a backslash. Backslash characters
> are also escaped in the string (with another backslash) to distinguish
> them from other escaped characters.
>
> I'm trying to split this string into its constituent fields. Based on
> the above, the delimiter is defined as a pipe-character that is not
> preceeded by an odd number of backslash characters (i.e. it's
> preceeded by zero or an even number of backslash characters).
this is a FAQ, of course.
but in your specific case,
> my $escape = '\\';
> my $separator = '|';
>
> my @fields =
split(/\Q$separator\E(?=(\Q$escape$escape\E)*[^\Q$escape\E])/,
> reverse $value);
> E.g. when trying to split string 'A|B\|C|D\\|E' (reverse =
> 'E|\\D|C|\B|A'), I'm hoping to get @fields = ('E', '\\D', 'C|\B',
> 'A'), but instead I get ('E', '\\', '\\D', '', 'C|\B', '', 'A').
>
> Can anyone tell me how I avoid getting these extra fields in the
> result?
your inner () group is interfering (interleaving) with the split.
try:
my @fields =
split(/\Q$separator\E(?=(?:\Q$escape$escape\E)*[^\Q$escape\E])/,
reverse $value);
gnari
>
> Thanks,
>
> Michael
------------------------------
Date: Mon, 31 May 2004 23:00:12 +0200
From: Xaver Biton <javier@t-online.de>
Subject: Re: splitting cvs file and insert in mysql via DBI
Message-Id: <c9g6cq$61u$04$1@news.t-online.com>
gnari wrote:
> "Xaver Biton" <javier@t-online.de> wrote in message
> news:c9fnr9$jlj$00$1@news.t-online.com...
>
>>Xaver Biton wrote:
>>
>>Ok I've enabled strict and warnings again but didn't chanche much. I've
>>a similar error:
>>
>>## error message##
>>
>>Can't call method "execute" on an undefined value at customers.pl line
>>26, <> line 1.
>>
>>##end##
>>
>>this is line 26: $sth->execute($vo_nr, $interne_customer_id, $nikname,
>>$salutation, $name,
>>$forename, $address, $zip, $city, $tel, $telefax, $customer_since, $mail);
>
>
> this is not a 'similar' error at all.
>
> this tells us that $sth is undefined at the moment of the call,
> probably because the prepare() failed. you should test the results
> of the DBI connect() and prepare() functions, especially when disabling
> DBI's RaiseError.
Hi,
this script make me crazy, I've checked everything, and everything is
ok. But was is surprising is that if I use a csv file with only 3 fields
it work! As soon I add onother field it doesn't work anymore.
Please help
Xaver
------------------------------
Date: Mon, 31 May 2004 23:19:55 +0200
From: Xaver Biton <javier@t-online.de>
Subject: Re: splitting cvs file and insert in mysql via DBI
Message-Id: <c9g7hp$77h$04$1@news.t-online.com>
HI,
oK, finally I know where's the problem.
If I use strict then I ricieve the folowing error:
Can't call method "execute" on an undefined value at cinque.pl line
22, <> line 1.
if I disable use strict everything work ok, hwy this?
hier an example:
use DBI;
use strict;
# Declare and initialize variables
my $host = '192.168.0.1';
my $db = 'proeweb';
my $db_user = 'web884';
my $db_password = 'xaverio';
# Connect to the requested server
my $dbh = DBI->connect("dbi:mysql:$db:$host", "$db_user", "$db_password",
{RaiseError => 0, PrintError => 0} );
my $sth = $dbh->prepare("INSERT INTO
test(erste,zweite,dritte,cinque,sei,sette) VALUES(?,?,?,?,?,?)");
while(<>){
chomp;
my ($erste,$zweite,$dritte,$cinque,$sei,$sette) = split /;/;
my $sth->execute($erste,$zweite,$dritte,$cinque,$sei,$sette);
}
------------------------------
Date: Mon, 31 May 2004 21:31:01 +0000 (UTC)
From: Ben Morrow <usenet@morrow.me.uk>
Subject: Re: splitting cvs file and insert in mysql via DBI
Message-Id: <c9g86l$ep$1@wisteria.csv.warwick.ac.uk>
Quoth Xaver Biton <javier@t-online.de>:
> HI,
>
> oK, finally I know where's the problem.
> If I use strict then I ricieve the folowing error:
>
> Can't call method "execute" on an undefined value at cinque.pl line
> 22, <> line 1.
>
> if I disable use strict everything work ok, hwy this?
>
> hier an example:
>
> use DBI;
> use strict;
use warnings;
>
> # Declare and initialize variables
> my $host = '192.168.0.1';
> my $db = 'proeweb';
> my $db_user = 'web884';
> my $db_password = 'xaverio';
>
> # Connect to the requested server
>
> my $dbh = DBI->connect("dbi:mysql:$db:$host", "$db_user", "$db_password",
> {RaiseError => 0, PrintError => 0} );
my $dbh = ... or die "connect failed: $DBI::errstr";
Or set RaiseError to 1.
> my $sth = $dbh->prepare("INSERT INTO
> test(erste,zweite,dritte,cinque,sei,sette) VALUES(?,?,?,?,?,?)");
my $sth = ... or die "prepare failed: $DBI::errstr";
> while(<>){
> chomp;
> my ($erste,$zweite,$dritte,$cinque,$sei,$sette) = split /;/;
You really want to use an array here:
my @values = split /;/;
> my $sth->execute($erste,$zweite,$dritte,$cinque,$sei,$sette);
What's that 'my' doing?
$sth->execute(@values) or die "execute failed: $DBI::errstr";
> }
Ben
--
Outside of a dog, a book is a man's best friend.
Inside of a dog, it's too dark to read.
ben@morrow.me.uk Groucho Marx
------------------------------
Date: 31 May 2004 21:43:04 GMT
From: "A. Sinan Unur" <1usa@llenroc.ude>
Subject: Re: splitting cvs file and insert in mysql via DBI
Message-Id: <Xns94FAB43CBC08Easu1cornelledu@132.236.56.8>
Xaver Biton <javier@t-online.de> wrote in
news:c9g7hp$77h$04$1@news.t-online.com:
> HI,
>
> oK, finally I know where's the problem.
> If I use strict then I ricieve the folowing error:
>
> Can't call method "execute" on an undefined value at cinque.pl line
> 22, <> line 1.
>
> if I disable use strict everything work ok, hwy this?
You have a serious problem: You blindly ignore possible error conditions
even when they are screaming at you. Fix your attitude please.
Very obviously, $sth is undefined. The fact that you choose not to be
informed of this does not make it go away.
> hier an example:
>
> use DBI;
> use strict;
use warnings;
> # Declare and initialize variables
> my $host = '192.168.0.1';
> my $db = 'proeweb';
> my $db_user = 'web884';
> my $db_password = 'xaverio';
Fix your indentation. This is giving the impression that there is a new
scope where there is none.
> my $dbh = DBI->connect("dbi:mysql:$db:$host", "$db_user",
> "$db_password", {RaiseError => 0, PrintError => 0} );
No point in all those extra quotation marks. But the thing that baffles me
is you again _CHOOSE_ not to be informed of errors. How can we guess what
went wrong with your database connection when you won't check it yourself?
As a first step, change the code above to:
my $dbh = DBI->connect(
"dbi:mysql:$db:$host", $db_user, $db_password,
{RaiseError => 1, PrintError => 1}
);
> my $sth = $dbh->prepare("INSERT INTO
> test(erste,zweite,dritte,cinque,sei,sette) VALUES(?,?,?,?,?,?)");
Again, no error checking ...
> while(<>){
> chomp;
> my ($erste,$zweite,$dritte,$cinque,$sei,$sette) = split /;/;
> my $sth->execute($erste,$zweite,$dritte,$cinque,$sei,$sette);
> }
If you had been checking for errors, you would have been told why the
prepare call above did not succeed (and hence why $sth is undefined). You
choose not to. How can we know what went wrong?
--
A. Sinan Unur
1usa@llenroc.ude (reverse each component for email address)
------------------------------
Date: Mon, 31 May 2004 21:36:37 -0000
From: "gnari" <gnari@simnet.is>
Subject: Re: splitting cvs file and insert in mysql via DBI
Message-Id: <c9g8dv$qu4$1@news.simnet.is>
"Xaver Biton" <javier@t-online.de> wrote in message
news:c9g6cq$61u$04$1@news.t-online.com...
> this script make me crazy, I've checked everything, and everything is
> ok. But was is surprising is that if I use a csv file with only 3 fields
> it work! As soon I add onother field it doesn't work anymore.
fine. take that, and chuck out the csv file reading part.
replace the whole while() loop with a single
$sth->execute('012346','foo','bar','hello');
does it work?
if yes, then it is not a DBI problem. try again with your
real data instead of foo and bar etc
if no, then take a look again at your prepare()
if you still cannot solve it, show us again a minimal script
with strictures and warnings, that exhibits your problem.
while you are at it, show us a working 3 field version of that
minimal script.
gnari
------------------------------
Date: Mon, 31 May 2004 21:43:15 -0000
From: "gnari" <gnari@simnet.is>
Subject: Re: splitting cvs file and insert in mysql via DBI
Message-Id: <c9g8qd$qva$1@news.simnet.is>
"Xaver Biton" <javier@t-online.de> wrote in message
news:c9g7hp$77h$04$1@news.t-online.com...
> HI,
>
> oK, finally I know where's the problem.
> If I use strict then I ricieve the folowing error:
>
> Can't call method "execute" on an undefined value at cinque.pl line
> 22, <> line 1.
>
> if I disable use strict everything work ok, hwy this?
what do you mean 'everything work ok' ?
> my $sth->execute($erste,$zweite,$dritte,$cinque,$sei,$sette);
this 'my' will undefine $sth, whether you use strict or not
gnari
------------------------------
Date: Mon, 31 May 2004 22:15:34 +0200
From: Matija Papec <perl@my-header.org>
Subject: Re: strange behavior
Message-Id: <r54nb0tuttnpaelqignfmto7rc74ifscrg@4ax.com>
X-Ftn-To: Michele Dondi
Michele Dondi <bik.mido@tiscalinet.it> wrote:
>> my $tmp = join ' ', map { $_ += 5*$row } 0 .. 4;
> ^^
>
>> print "$row - $tmp\n";
>> }
>>
>>---------- Capture Output ----------
>>2 - 10 11 12 13 14
>>2 - 20 21 22 23 24
>>2 - 30 31 32 33 34
>>2 - 40 41 42 43 44
>
>Althoug that += is strange and unneeded, I can't understand why you
>get that output and I'd say it's not correct. However I get it too!
>(perl 5.8.3 here)
I guess then, these who have older perls can stay at their rest since all
versions are acting like this. :)
>But then do you have a good reason for not using
>
> map { $_ + 5*$row } 0..4;
>
>instead?
I wanted to keep code readable so,
my $tmp = join ' ', map { $_+=5*$row; "<!--FTD-$_-->" } 0 .. 4;
was more appealing then,
my $tmp = join ' ', map "<!--FTD-". $_+5*$row ."-->", 0 .. 4;
--
Secure and instant E-pay for web shops
http://www.ouroboros.hr/?e-placanje
------------------------------
Date: Mon, 31 May 2004 22:20:40 +0200
From: Matija Papec <perl@my-header.org>
Subject: Re: strange behavior
Message-Id: <nk4nb0l6a8oc84jdkjkrju5v7r957976cr@4ax.com>
X-Ftn-To: Bill
Bill <wherrera@lynxview.com> wrote:
>> Hm, but 0..4 isn't an array; it is a _list_ which gets cached and AFAIK it
>> shouldn't behave like that?
>>
>This is perl5-porters stuff. It's beyond me. I'd comment that IMO 0 .. 4
>should be constant, and assigning to it should be a run time error. But
>that's _my_ perl implementation, which exists only in my head (just as
>well too :) ).
I think that explicit lists are rising run time error and ranges are not,
but I can't put my hand in fire on that. ;)
--
Secure and instant E-pay for web shops
http://www.ouroboros.hr/?e-placanje
------------------------------
Date: Mon, 31 May 2004 20:47:00 +0000 (UTC)
From: Ben Morrow <usenet@morrow.me.uk>
Subject: Re: strange behavior
Message-Id: <c9g5k4$rid$1@wisteria.csv.warwick.ac.uk>
Quoth Matija Papec <perl@my-header.org>:
> X-Ftn-To: Michele Dondi
>
> Michele Dondi <bik.mido@tiscalinet.it> wrote:
> >> my $tmp = join ' ', map { $_ += 5*$row } 0 .. 4;
> > ^^
> >
> >> print "$row - $tmp\n";
> >> }
> >>
> >>---------- Capture Output ----------
> >>2 - 10 11 12 13 14
> >>2 - 20 21 22 23 24
> >>2 - 30 31 32 33 34
> >>2 - 40 41 42 43 44
> >
> >Althoug that += is strange and unneeded, I can't understand why you
> >get that output and I'd say it's not correct. However I get it too!
> >(perl 5.8.3 here)
>
> I guess then, these who have older perls can stay at their rest since all
> versions are acting like this. :)
>
> >But then do you have a good reason for not using
> >
> > map { $_ + 5*$row } 0..4;
> >
> >instead?
>
> I wanted to keep code readable so,
>
> my $tmp = join ' ', map { $_+=5*$row; "<!--FTD-$_-->" } 0 .. 4;
> was more appealing then,
>
> my $tmp = join ' ', map "<!--FTD-". $_+5*$row ."-->", 0 .. 4;
But what's wrong with
... map { my $x = $_ + 5*$row; "<!--FTD-$x-->" } ...
?
Ben
--
Outside of a dog, a book is a man's best friend.
Inside of a dog, it's too dark to read.
ben@morrow.me.uk Groucho Marx
------------------------------
Date: 31 May 2004 11:36:21 -0700
From: krakle@visto.com (krakle)
Subject: Re: Using Cookies With Perl
Message-Id: <237aaff8.0405311036.40151b5e@posting.google.com>
Tad McClellan <tadmc@augustmail.com> wrote in message news:<slrncb7eri.v89.tadmc@magna.augustmail.com>...
> krakle <krakle@visto.com> wrote:
> > Uri Guttman <uri@stemsystems.com> wrote in message news:<x71xl9nnmg.fsf@mail.sysarch.com>...
> >> >>>>> "k" == krakle <krakle@visto.com> writes:
> >>
> >> k> "James Hunt" <jameskorea2003@hotmail.com> wrote in message news:<d6udnXeKBqsK9y_dRVn-hQ@comcast.com>...
> >> >> Does anyone have a good web reference for setting up and accessing cookies
> >> >> with Perl?
> >> >>
> >> >> - James Hunt
> >>
> >> k> This isn't a Perl question and has no excuse to be here.
> >> k> Right on Tad?
> >>
> >> nope. you lose again. he asked a specific question about how to do
> >> something in perl.
> >
> > Wrong I asked how to do sessions in Perl.
>
>
> No you didn't.
>
> You asked, in your characteristic sloppy English: *etc. blah boo boo blah blah*
Ok Tad no need to go off topic in this thread now. We have already
went over all details in the other thread. Take care. :)
------------------------------
Date: 31 May 2004 11:40:59 -0700
From: constants@mix-net.net (Mark Constant)
Subject: Re: Why is this upload script not working
Message-Id: <ce43fdea.0405311040.6d025319@posting.google.com>
Well the script finally uploads a file which is great. Only one
problem It uploads without the -T switch which means the file is not
untainted. I have looked at perlsec(1) and I am somewhat still curious
as to why this is not getting untainted. Also I have one other
question. Is there a way to let the user now how long the upload will
take. I am going to have them upload 50 meg files so I will like the
uploader.cgi to give an approximate time of how long it will take.
Thanks.
#!/usr/bin/perl -T
use CGI;
use CGI::Carp qw/fatalsToBrowser/;
use strict;
use warnings;
use Cwd;
use Cwd 'abs_path';
my $q = CGI->new();
my $file = $q->param('upfile');
$file =~ /^([\w.-]+)$/ or die "Unaccetable file name: $file";
my $filename = $1;
my $cdir = cwd;
chdir('/var/www/htdocs/quickbooks/') or die "Can't cd to quickbooks
dir: $!";
my $dir = cwd;
my $path = abs_path $file;
print $q->header, $q->start_html('Uploading File');
print $q->h1('Upload Results');
if(!$file){
print "Nothing Uploaded\n";
} else {
print "Filename: $file<br />\n";
print "Destination: $path<br />\n";
print "Original CWD was: $cdir<br />\n";
print "New CWD after chdir is: $dir<br />\n";
my $ctype = $q->uploadInfo($file)->{'Content-Type'};
print "MIME Type: $ctype<br />\n";
open(OUTFILE, ">$path") or die("Didn't work because of $! \n");
binmode(OUTFILE);
my ($read, $buffer);
print OUTFILE $buffer
while $read = read $file, $buffer, 1024;
defined $read or die "read failed: $!";
close OUTFILE or die "Close of uploaded file failed: $!";
close $file or die "Close of socked failed $!";
print "File saved\n";
}
$q->end_html;
------------------------------
Date: 31 May 2004 11:50:00 -0700
From: krakle@visto.com (krakle)
Subject: Re: Why is this upload script not working
Message-Id: <237aaff8.0405311050.4f8570c6@posting.google.com>
constants@mix-net.net (Mark Constant) wrote in message news:<ce43fdea.0405271651.17bb245@posting.google.com>...
> I looked at a couple of scripts on how to upload a file and came up
> with the script below. Now the script acts like it uploaded the file
> by not giving errors but when I check the directory no file is there.
> The script runs from /cgi-bin/ and the quickbooks directory is chmod
> 755.
> What I am trying to do is upload a quickbooks file that is 50mbs.
Perhaps the server has set a limit. By the way this isn't a Perl
question.
> Here are the most important parts. I only left out how I got the time
> and date.
>
> #!/usr/bin/perl
Wheres the -Tw switches?
> use CGI;
Where's the use of the strict pragma?
> $q = new CGI;
> $file = $q->param("upfile");
> $dir = "../htdocs/quickbooks";
> $filename = "$file-$date-$time";
No scoping of variables?
>
> print $q->header, $q->start_html("Uploading File");
> print $q->h1("Upload Results");
>
> if(!file){
file? $file?
blah blah blah. I hope you didn't goto cgi-101.... Pick up a Perl book
off the shelf.
------------------------------
Date: Mon, 31 May 2004 16:16:02 -0400
From: Sherm Pendley <spamtrap@dot-app.org>
Subject: Re: Why is this upload script not working
Message-Id: <XKGdnXCZnpQYDybd4p2dnA@adelphia.com>
krakle wrote:
> By the way this isn't a Perl question.
Why do you keep going on about that? You're acting like a child who's candy
has been taken away. Please stop whining.
It's easy to decide what is or is not a Perl question. If the answer would
be the same if some other language were being used, then it's not a Perl
question. Simple.
For example, if the question is "how do I make the text output of my CGI
appear in red?" then the answer is the same, regardless of whether the CGI
is written in Perl, C, Python, or whatever: Use the appropriate HTML/CSS
markup. It's a question about the HTML that's being produced, not about the
language that's being used to produce it.
On the other paw, if the question were "if I'm using CGI.pm's HTML functions
to produce output, how do I add a style attribute to an element?" then that
*is* a Perl question. It's a question about the Perl code that's being used
to generate the HTML, not a question about the HTML itself.
The distinction is important because not everyone who knows Perl well will
necessarily know HTML/CSS. If the question is *really* about HTML, or HTTP,
or CSS, or whatever, then better answers can usually be found by asking
folks who are knowledgeable in that area, instead of asking Perl folks.
Similarly, you wouldn't want to ask a Perl question in an HTML group - even
if the Perl in question happened to produce HTML as output.
sherm--
--
Cocoa programming in Perl: http://camelbones.sourceforge.net
Hire me! My resume: http://www.dot-app.org
------------------------------
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 6635
***************************************