[24435] in Perl-Users-Digest
Perl-Users Digest, Issue: 6619 Volume: 10
daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Fri May 28 03:05:42 2004
Date: Fri, 28 May 2004 00:05:07 -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 Fri, 28 May 2004 Volume: 10 Number: 6619
Today's topics:
Re: (repost) Math problem - converting between arbitrar <ToGroun@NotTo.me>
Re: (repost) Math problem - converting between arbitrar (Jay Tilton)
Re: Anonymous <net.weathersongATnemo>
Re: Handling Environmental variables <jurgenex@hotmail.com>
help mandreke 9.2 urpmi and perl_base How? <aletia@2vias.com.ar>
Re: line wrap with encode('MIME-Header', "foo") <wherrera@lynxview.com>
Re: Listing files sorted by creation time <tadmc@augustmail.com>
Re: Making sure that we're dealing with an array (refer <troc@pobox.com>
On "for (@foo)" <please_post@nomail.edu>
Re: On "for (@foo)" <usenet@morrow.me.uk>
Re: Problem installing modules <randy@theoryx5.uwinnipeg.ca>
Re: Regular Expressions <usenet@morrow.me.uk>
Re: Regular Expressions (Malcolm Dew-Jones)
Re: Regular Expressions <tore@aursand.no>
Re: Regular Expressions <uri@stemsystems.com>
Re: Regular Expressions <jeffplus@comcast.net>
Re: Remove first letter of each string in array <uri.guttman@fmr.com>
Re: Why is this upload script not working <usenet@morrow.me.uk>
Re: Why is this upload script not working <tore@aursand.no>
Re: xml type parser in the standard perl installation ? <aletia@2vias.com.ar>
Re: xml type parser in the standard perl installation ? <matrix_calling@yahoo.dot.com>
Digest Administrivia (Last modified: 6 Apr 01) (Perl-Users-Digest Admin)
----------------------------------------------------------------------
Date: Fri, 28 May 2004 01:39:21 GMT
From: " ! aaa" <ToGroun@NotTo.me>
Subject: Re: (repost) Math problem - converting between arbitrary bases in perl - help!
Message-Id: <e786d3df61a7618fa8ce311217e94023@news.teranews.com>
Thanks!... but... I forgot to specifically mention that I want arbitrary
precision - oops!!! (though I did mention bigmath - but I'd prefer
to exclude that giant library if possible - I'm trying to build something
"lightweight").
I'm wanting at least 40 binary bits precision initially, probably upto 128
in the
very near term, then more later (to convert ascii (base 128 or base 256) to
efficient transfer characters: base94, 74-digit lines)- hence my "strange"
code
in the middle that worked through the input string scalar and attempted to
build
the output into a string scalar using nothing more than integers. Note
"attempted"
- the output building fails probably because I'm not even sure if this is
possible to
do.
Math::BaseCalc only functions on CPU datatypes, so doesn't seem useful :-(
"thundergnat" <thundergnat@hotmail.com> wrote in message
news:40b65688$0$3135$61fed72c@news.rcn.com...
> ! aaa wrote:
> > I Posted earlier to Newsgroups: comp.lang.perl,alt.perl,alt.math,
> > but this looks like the more appropriate place in hindsight...
> >
> >
> > Hi all - I've been trying to write a small sub to convert form an input
base
> > (eg: 16) to an output base (eg:64) and back.
> >
> > The reason is that I need to communicate tristate (base 3) data
efficiently
> > via DNS (base 37 a-z0-9 and '-').
> >
> > I *could* do it by converting into a "bigmath binary" structure I guess,
but
> > I thought there might be a more elegant way...
> >
> > but such a solution eludes me.
> >
> > Can anyone think how to approach the problem?
> >
>
> Hmmm. I was intrigued and whomped this subroutine together to do base
> conversions. I used your "digit" sequence but was having a hard time
> following your logic, so I wrote the rest from scratch. It isn't as
> efficient as it could be, but it works.
>
> One comment on your script, whitespace is cheap, don't be afraid to use
it.
>
>
> Any lines in the subroutine that aren't indented at least 4 spaces are
> part of the previous line. You may need to rejoin them for the script to
> work. (News reader wrapping) I broke a few of the lines up to fit in
> without wrapping.
>
>
>
> #!/usr/bin/perl
>
> use strict;
> use warnings;
>
> # Convert any arbitrary base number (up to base 94) to any other
> # arbitrary base. Feed the subroutine the base of the existing number,
> # the desired base and the the number to be converted. This will
> # probably be inaccurate for anthing larger than 32 bit (or whatever
> # your native integer is.) If you need larger numbers, you can probably
> # adapt this to use Math::BigInt without too much pain.
>
>
> print baseconvert( 16, 10, 'C0DECAFE' ), "\n";
>
> sub baseconvert{
> my ( $from_base, $to_base, $data) = @_;
> my $digit_sequence = '0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ'.
> 'abcdefghijklmnopqrstuvwxyz!"#$%&\'()*+,-./:;<=>?@[\]^'.
> '_`{|}~'; # 94 "digits"
> my $from_digits = substr( $digit_sequence, 0, $from_base );
> my $to_digits = substr( $digit_sequence, 0, $to_base );
> my $number = '';
>
> # convert to base 10 integer
> my $integer = 0;
> my @digit_array = reverse split //, $data;
> for ( 0 .. $#digit_array ){
> die "$data is not a valid base $from_base number."
> if ( index( $from_digits, $digit_array[$_]) < 0 );
> $integer +=
> index( $from_digits, $digit_array[$_] ) * $from_base ** $_;
> }
>
> # then convert to arbitrary base
> while ( $integer > 0 ){
> my $digit = $integer % $to_base;
> $number = substr( $to_digits, $digit, 1 ) . $number;
> $integer = int( $integer / $to_base );
> }
> return $number;
> }
------------------------------
Date: Fri, 28 May 2004 03:11:57 GMT
From: tiltonj@erols.com (Jay Tilton)
Subject: Re: (repost) Math problem - converting between arbitrary bases in perl - help!
Message-Id: <40b6a6e1.288122688@news.erols.com>
[Please don't top-post replies. Please trim reply quoted material to the
minimum necessary to establish context. See the clpm posting guidelines
for other useful advice.]
" ! aaa" <ToGroun@NotTo.me> wrote:
: Thanks!... but... I forgot to specifically mention that I want arbitrary
: precision - oops!!! (though I did mention bigmath - but I'd prefer
: to exclude that giant library if possible - I'm trying to build something
: "lightweight").
:
: I'm wanting at least 40 binary bits precision initially, probably upto 128
: in the very near term, then more later
: Math::BaseCalc only functions on CPU datatypes, so doesn't seem useful :-(
But the code in Math::BaseCalc provides a nice template (superclass, even)
for creating a module that handles arbitrary precision. Just alter one
Math::BaseCalc method to handle bigints and let the overloaded math
operators in Math::BigInt do the Right Thing.
#!perl
use warnings;
use strict;
{{
package Math::BaseCalc::BigInt;
use base 'Math::BaseCalc';
use Math::BigInt;
sub from_base {
my $self = shift;
my $dignum = @{$self ->{digits}};
my $result = Math::BigInt ->new(0);
my $str = reverse shift;
$result = $result * $dignum + $self ->{trans}{chop $str}
while length($str);
return $result;
}
}}
my $b03 = Math::BaseCalc::BigInt ->new(digits => [0..2]);
my $b37 = Math::BaseCalc::BigInt ->new(digits => ['a'..'z',0..9,'-']);
my $i = '1' x 2000; # huge number, even in trinary.
my $j = $b37 -> to_base( $b03 ->from_base( $i ) );
__END__
------------------------------
Date: Fri, 28 May 2004 04:42:10 GMT
From: David Frauzel <net.weathersongATnemo>
Subject: Re: Anonymous
Message-Id: <d4db916d2f886841493e51cda6677d82@news.teranews.com>
Ben Morrow <usenet@morrow.me.uk> wrote in
news:c96214$a0f$1@wisteria.csv.warwick.ac.uk:
> Does this make things clearer?
Ah, reference counting. That makes more sense, yes. No need to worry about
dereferencing something that no longer exists.
Except now I'm again uncertain about anonymous array. :p
Is this:
['foo', 'bar']
An anonymous array, or a *reference* to an anonymous array? (Which is what
I meant originally about anonymous arrays and references being
inseperable.)
I get the feeling now that there's no such thing as "just" an anonymous
array, only references to them.
What I mean is:
# Passes an array (as a list)
&foo @bar;
# Passes a list
&foo +('foo', 'bar');
# Passes a reference
&foo ['foo', 'bar'];
So "anonymous" doesn't just mean unnamed, it also implicates a reference?
(But I get the idea they wouldn't be possible otherwise.)
------------------------------
Date: Fri, 28 May 2004 02:53:27 GMT
From: "Jürgen Exner" <jurgenex@hotmail.com>
Subject: Re: Handling Environmental variables
Message-Id: <HQxtc.11608$nJ6.8815@nwrddc02.gnilink.net>
Satish wrote:
> How do I set/unset unix environmental variables from a perl script?
"perldoc perlvar" and check the %ENV hash.
"perldoc -q environment" might be interesting, too.
jue
------------------------------
Date: Fri, 28 May 2004 01:38:57 -0300
From: chanio <aletia@2vias.com.ar>
Subject: help mandreke 9.2 urpmi and perl_base How?
Message-Id: <2hnu32FenqaqU2@uni-berlin.de>
Hi there,
I have being foolishly upgrading some rpms from my original mdk 9.2.
Now I have lost my Perl::Magick.PM for doing scripts with ImageMagick.
It seems that I foolishly upgraded ImageMagick.
Now, my perl RC version doesn't work any longer with the new ImageMagick. So
I have lost (for incompatibility reasons) the PerlMagick.PM.
When I want to reinstall (or upgrade) this PM the urpmi says that I need to
upgrade my perl_base. How could I do this without loosing all connection
with the uprmi (it works with perl)?
When I try to upgrade perl_base the urpmi declares nearly 80Mb of implied
rpms that need to be downloaded. And afterwards, it says that it needs to
remove Drakupdate, and other vital programs.
It doesn't work either with cpan. It fails.
I am scared, sorry. How does mdk do it?
Is there anything else that I could do without having to downgrade
ImageMagick (and perhaps other related things) ?
TIA
--
.------------------. -.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.
| ___ _ _ _ _ | ALBERTO ADRIAN SCHIANO - ARGENTINA - 2004
|/ __/ | \ || | | | <ALETIA@2VIAS.COM.AR> # 34-34S 058-25W(z-3)
|||_< \| || ' | | +------------+------------------------------
|`____/|_\_|`___' | LINUX COUNTER: 240 133 ~ machine : 119 401
| _ _ _ __ _ | +------------+----------+-------------------
|| | | \ |\ \/ | AMD Athlon 6 |RAM 512Mb.|krnl.: 2.6.3-10mdk
|| |_ | | \ \ | i586-mandrake-linux-gnu |MDK 9.2 - KDE 3.13
||___||_\_|_/\_\ | +-----------------------+-------------------
| __ __ ___ _ _ | Maxtor #4D040H2 32Gb. |DISPLAY_VGA SiS 630
|| \ \| . \| / | ------------------------+--+----------------
|| || | || \ | PCI Audio snd-trident 7018 | ViewSonic E771
||_|_|_||___/|_\_ | ---------------------------+----------------
| | http://perlmonks.org/index.pl?node_id=245320
'------------------' -.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.
------------------------------
Date: Thu, 27 May 2004 22:03:10 -0600
From: Bill <wherrera@lynxview.com>
Subject: Re: line wrap with encode('MIME-Header', "foo")
Message-Id: <eYGdnayotbicJyvdRVn-ug@adelphia.com>
Axel Hanusch wrote:
> Hi,
> when I do this
>
> use Encode "encode";
> print encode('MIME-Header', 'Subject: blah blah blah blah blah blah \
> blah blah blah blah blah foo@bar.org blah')."\r\n";
>
> I get this result:
>
> Subject: blah blah blah blah blah blah blah blah blah blah blah foo@bar.
> org blah
>
> The line is folded after the '.' and when the receiving email client
> unfolds it according to RFC 822 (Section 3.1.1.), the result is "...blah
> foo@bar. org blah" instead of "...blah foo@bar.org blah".
>
> Why are lines folded at characters like ()<>@,;:"'/[]?.= and not at
> whitespaces?
>
Maybe a bug, but long subject lines should be encoded in chunks anyway.
See the example specs for MIME-Header in the RFC.
>
> Thanks in advance,
>
> Axel
>
RFC 2047:
(=?ISO-8859-1?Q?a?= (ab)
=?ISO-8859-1?Q?b?=)
Any amount of linear-space-white between 'encoded-word's,
even if it includes a CRLF followed by one or more SPACEs,
is ignored for the purposes of display.
Perhaps you might try splitting a long subject line yourself and encode
the pieces?
--HTH
------------------------------
Date: Thu, 27 May 2004 20:51:55 -0500
From: Tad McClellan <tadmc@augustmail.com>
Subject: Re: Listing files sorted by creation time
Message-Id: <slrncbd6pr.cto.tadmc@magna.augustmail.com>
Yash <yashgt@yahoo.com> wrote:
> with the latest created file taken first.
^^^^^^^
Many filesystems (such as *nix) do not record the creation time.
Perl gives you access to 3 timestamps (perldoc -f stat), none
of them can be counted on to be the creation time.
The other followups I've seen in this thread use "modified"
where your spec said "created".
--
Tad McClellan SGML consulting
tadmc@augustmail.com Perl programming
Fort Worth, Texas
------------------------------
Date: Fri, 28 May 2004 03:57:39 GMT
From: Rocco Caputo <troc@pobox.com>
Subject: Re: Making sure that we're dealing with an array (reference)
Message-Id: <slrncbdept.hdf.troc@eyrie.homenet>
On Thu, 27 May 2004 18:24:13 +0200, Tore Aursand wrote:
>
> Currently, I'm stuck with code like this:
>
> my $paths = $ARGS{'paths'} || [];
> $paths = ( ref($paths) eq 'ARRAY' ) ? $paths : [ $paths ];
>
> It seems to work, though, but I feel that there's something wrong with
> this approach...?
If you usually expect $ARGS{paths} to be an array reference, then most
of the time your code will be the equivalent of $paths = $paths. That
sort of inefficiency displeases me. I'd throw out the C-style ?:
operator and instead go with something more Perly. Like this:
my $paths = $ARGS{'paths'} || [];
$paths = [ $paths ] unless ref($paths) eq 'ARRAY';
-- Rocco Caputo - http://poe.perl.org/
------------------------------
Date: Fri, 28 May 2004 01:35:56 +0000 (UTC)
From: bill <please_post@nomail.edu>
Subject: On "for (@foo)"
Message-Id: <c9651s$78s$1@reader2.panix.com>
Something like this burned me really bad once:
my @x = (1) x 3;
print "@x\n";
for my $y (@x) {
$y = 0;
}
print "@x\n";
__END__
1 1 1
0 0 0
It's as if the loop variable $y was a reference to the current
element of the array, except that it doesn't need to be dererenced.
Surprisingly, to me at least, this doesn't produce any errors:
for my $y (1..3) {
$y = 0;
}
Perl doesn't see the above as analogous to
1 = 0; # triggers "Can't modify constant item" error
OK, now, in an expression like this
for my $x (@X) {
# etc.
}
I assume that Perl keeps track of the index on @X correponding to
the current element. Is there a way to access this "current index"
from within a Perl program?
Thanks!
-bill
------------------------------
Date: Fri, 28 May 2004 02:09:01 +0000 (UTC)
From: Ben Morrow <usenet@morrow.me.uk>
Subject: Re: On "for (@foo)"
Message-Id: <c966vt$bkc$1@wisteria.csv.warwick.ac.uk>
Quoth bill <please_post@nomail.edu>:
>
> Something like this burned me really bad once:
>
> my @x = (1) x 3;
> print "@x\n";
> for my $y (@x) {
> $y = 0;
> }
> print "@x\n";
> __END__
> 1 1 1
> 0 0 0
>
> It's as if the loop variable $y was a reference to the current
> element of the array, except that it doesn't need to be dererenced.
Yes.
> Surprisingly, to me at least, this doesn't produce any errors:
>
> for my $y (1..3) {
> $y = 0;
> }
>
> Perl doesn't see the above as analogous to
>
> 1 = 0; # triggers "Can't modify constant item" error
No: an array element is an lvalue, and modifiable.
> OK, now, in an expression like this
>
> for my $x (@X) {
> # etc.
> }
>
> I assume that Perl keeps track of the index on @X correponding to
> the current element. Is there a way to access this "current index"
> from within a Perl program?
No, it simply keeps track of the current element. From that it can find
the next one.
Ben
--
"The Earth is degenerating these days. Bribery and corruption abound.
Children no longer mind their parents, every man wants to write a book,
and it is evident that the end of the world is fast approaching."
-Assyrian stone tablet, c.2800 BC ben@morrow.me.uk
------------------------------
Date: Thu, 27 May 2004 23:13:38 -0500
From: "Randy Kobes" <randy@theoryx5.uwinnipeg.ca>
Subject: Re: Problem installing modules
Message-Id: <U%ytc.10561$gf1.25971@news1.mts.net>
"Thomas Schweikle" <tpsX@vr-web.de> wrote in message
news:2hkqv4Fe44e2U1@uni-berlin.de...
> Randy Kobes wrote:
>
> > "Thomas Schweikle" <tpsX@vr-web.de> wrote in message
> > news:2h8v2bFa4ccrU1@uni-berlin.de...
> >> J. Gleixner wrote:
> >> > Can be found at http://theoryx5.uwinnipeg.ca/ppms/AppConfig.ppd
> >>
> >> OK! Thanks! This worked. But now I am missing four additional packages:
> >>
> >> CGI --- I need v2.93 the repository only has 2.81
> >> Date::Format --- not found
> >> Template --- not found
> >> Chart::Base --- not found
> >>
> >> Where can I find them, or, how can I build my own working ppm-module
> >> installable via ActivePerl PPM?
> >
> > I've made up ppm packages of them, which you can install by adding
> > http://theoryx5.uwinnipeg.ca/cgi-bin/ppmserver?urn:/PPMServer58
> > to your repository list within the ppm shell (for ActivePerl 8xx).
>
> This doesn't work. ppm gives some fatal error. It is killed by the
> operating system afterwards. It is not possible to add the repository!
What happens when you try
C:\> ppm
ppm> rep add theoryx5
http://theoryx5.uwinnipeg.ca/cgi-bin/ppmserver?urn:/PPMServer58
ppm> install CGI.pm
ppm> install TimeDate
ppm> install Template-Toolkit
ppm> install Chart
ppm> quit
(the 2nd command line has been broken over 2 lines for readability).
If this doesn't work, can you use the ppm shell to install packages
from ActiveState's (default) repository?
best regards,
randy kobes
------------------------------
Date: Fri, 28 May 2004 01:06:54 +0000 (UTC)
From: Ben Morrow <usenet@morrow.me.uk>
Subject: Re: Regular Expressions
Message-Id: <c963be$ada$2@wisteria.csv.warwick.ac.uk>
Quoth "John Baro" <johnb@NixSpaMiprimus.com.au.com.au>:
> Apologies if this is the wrong group.
>
> I want to match 2 or more items within a string
>
> ie match string is "abc"
> To match
> "abc" -no match
> "abcabc" -match
> "abcdefabc" -match
> "abcabcabc" -match
>
> Any help would be appreciated.
> I could get each match of abc individually and check if there are two or
> more but would prefer to execute in one statement.
/(?: abc .* ){2,}/x
Ben
--
It will be seen that the Erwhonians are a meek and long-suffering people,
easily led by the nose, and quick to offer up common sense at the shrine of
logic, when a philosopher convinces them that their institutions are not based
on the strictest morality. [Samuel Butler, paraphrased] ben@morrow.me.uk
------------------------------
Date: 27 May 2004 20:33:34 -0800
From: yf110@vtn1.victoria.tc.ca (Malcolm Dew-Jones)
Subject: Re: Regular Expressions
Message-Id: <40b6b30e@news.victoria.tc.ca>
John Baro (johnb@NixSpaMiprimus.com.au.com.au) wrote:
: Apologies if this is the wrong group.
: I want to match 2 or more items within a string
: ie match string is "abc"
: To match
: "abc" -no match
: "abcabc" -match
: "abcdefabc" -match
: "abcabcabc" -match
: Any help would be appreciated.
: I could get each match of abc individually and check if there are two or
: more but would prefer to execute in one statement.
One possibility (not necessarily the best) but flexible.
$string = "abc";
$To_match="abc";
print "To_Match=$To_match\n";
print "$To_match matches $string\n"
if $To_match =~ s/\Q$string/$string/g >= 2;
$To_match="abcabc" ;
print "To_Match=$To_match\n";
print "$To_match matches $string\n"
if $To_match =~ s/\Q$string/$string/g >= 2;
$To_match="abcdefabc" ;
print "To_Match=$To_match\n";
print "$To_match matches $string\n"
if $To_match =~ s/\Q$string/$string/g >= 2;
$To_match="abcabcabc" ;
print "To_Match=$To_match\n";
print "$To_match matches $string\n"
if $To_match =~ s/\Q$string/$string/g >= 2;
------------------------------
Date: Fri, 28 May 2004 06:59:02 +0200
From: Tore Aursand <tore@aursand.no>
Subject: Re: Regular Expressions
Message-Id: <pan.2004.05.28.04.06.00.247736@aursand.no>
On Fri, 28 May 2004 01:06:54 +0000, Ben Morrow wrote:
>> ie match string is "abc"
>> To match
>> "abc" -no match
>> "abcabc" -match
>> "abcdefabc" -match
>> "abcabcabc" -match
> /(?: abc .* ){2,}/x
I'm no regular expression expert, but won't this be enough?
/(abc){2,}/
...or?
--
Tore Aursand <tore@aursand.no>
"There are three kinds of lies: lies, damn lies, and statistics."
(Benjamin Disraeli)
------------------------------
Date: Fri, 28 May 2004 05:08:50 GMT
From: Uri Guttman <uri@stemsystems.com>
Subject: Re: Regular Expressions
Message-Id: <x7y8nddtpa.fsf@mail.sysarch.com>
>>>>> "TA" == Tore Aursand <tore@aursand.no> writes:
TA> On Fri, 28 May 2004 01:06:54 +0000, Ben Morrow wrote:
>>> ie match string is "abc"
>>> To match
>>> "abc" -no match
>>> "abcabc" -match
>>> "abcdefabc" -match
>>> "abcabcabc" -match
>> /(?: abc .* ){2,}/x
TA> I'm no regular expression expert, but won't this be enough?
TA> /(abc){2,}/
that will match 'abcabcabc'. but what about the possible stuff between
the 'abc's? that is what the .* does. the ?: is just an efficiency thing
making sure no grabbing done since it is not needed.
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: Fri, 28 May 2004 01:47:47 -0400
From: Jeff Schwab <jeffplus@comcast.net>
Subject: Re: Regular Expressions
Message-Id: <5cWdnfDTYKbfTyvdRVn-jg@comcast.com>
John Baro wrote:
> Apologies if this is the wrong group.
>
> I want to match 2 or more items within a string
>
> ie match string is "abc"
> To match
> "abc" -no match
> "abcabc" -match
> "abcdefabc" -match
> "abcabcabc" -match
>
> Any help would be appreciated.
> I could get each match of abc individually and check if there are two or
> more but would prefer to execute in one statement.
>
> Cheers
> JB
>
>
sub matches_at_least_twice( $$ ) { (my @a = $_[0] =~ /$_[1]/g) > 1 }
------------------------------
Date: 27 May 2004 12:21:43 -0400
From: Uri Guttman <uri.guttman@fmr.com>
Subject: Re: Remove first letter of each string in array
Message-Id: <li3c5l96y0.fsf@localhost.localdomain>
>>>>> "!a" == ! aaa <!> writes:
!a> reverse() and then chop() might be more efficient ?
!a> otherwise, the whole thing need to get shifted around in memory all the
!a> time.
not exactly. perl is smart about losing stuff from the beginning of
strings and arrays. it moves a pointer to beyond the deleted entries and
doesn't shift down the rest unless it thinks it needs to do a realloc.
uri
------------------------------
Date: Fri, 28 May 2004 01:05:22 +0000 (UTC)
From: Ben Morrow <usenet@morrow.me.uk>
Subject: Re: Why is this upload script not working
Message-Id: <c9638i$ada$1@wisteria.csv.warwick.ac.uk>
Quoth constants@mix-net.net (Mark Constant):
> 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.
> Here are the most important parts. I only left out how I got the time
> and date.
>
> #!/usr/bin/perl
> use CGI;
> $q = new CGI;
> $file = $q->param("upfile");
> $dir = "../htdocs/quickbooks";
> $filename = "$file-$date-$time";
>
> print $q->header, $q->start_html("Uploading File");
> print $q->h1("Upload Results");
>
> if(!file){
> print "Nothing Uploaded\n";
> } else {
> print "Filename: $filename<br />\n";
> $ctype = $q->uploadInfo($file)->{'Content-Type'};
> print "MIME Type: $ctype<br />\n";
> open(OUTFILE, ">$dir/$filename") or dienice("Can't upload file: $!
> \n");
Does this open succeed? If the directory you are copying to has 755
permissions I would be slightly surprised: I would have expected that
Apache would run as a different user requiring you to give 777
permissions.
> binmode(OUTFILE);
> while (my $bytesread = read($file, $buffer, 1024)) {
> print OUTFILE $buffer;
> }
You can do this more easily with
local $/ = \1024;
print OUTFILE $_ while <$file>;
I would also check each read, as you're reading from a socket:
local $/ = \1024;
undef $!;
while (<$file>) {
print OUTFILE $_;
}
continue {
undef $!;
}
$! and dienice "read failed: $!";
> close(OUTFILE);
Just to be sure, check for errors:
close OUTFILE or dienice "can't close $filename: $!";
Ben
--
All persons, living or dead, are entirely coincidental.
ben@morrow.me.uk Kurt Vonnegut
Razors pain you / Rivers are damp
------------------------------
Date: Fri, 28 May 2004 05:53:47 +0200
From: Tore Aursand <tore@aursand.no>
Subject: Re: Why is this upload script not working
Message-Id: <pan.2004.05.28.03.44.54.832497@aursand.no>
On Thu, 27 May 2004 17:51:59 -0700, Mark Constant wrote:
> #!/usr/bin/perl
#!/usr/bin/perl -T
use strict;
use warnings;
> $q = new CGI;
> $file = $q->param("upfile");
> $dir = "../htdocs/quickbooks";
> $filename = "$file-$date-$time";
my $q = CGI->new();
my $file = $q->param( 'upfile' ); # Stick with one OO "style"
my $dir = '../htdocs/quickbooks'; # No need for double quotes
> print $q->header, $q->start_html("Uploading File");
> print $q->h1("Upload Results");
Useless use of double quotes (twice).
> if(!file){
Sure you mean 'file' and not '$file'? And why not keep it a bit more
English and write 'unless ( $file )' instead...?
As for why the upload seems to work, but there's not file created, I
really don't know. Are you _sure_ that your 'dienice' routine traps
everything it should?
What happens when you turn on taint mode (ie. '-T')?
--
Tore Aursand <tore@aursand.no>
"There are three kinds of lies: lies, damn lies, and statistics."
(Benjamin Disraeli)
------------------------------
Date: Fri, 28 May 2004 01:33:19 -0300
From: chanio <aletia@2vias.com.ar>
Subject: Re: xml type parser in the standard perl installation ?
Message-Id: <2hntogFenqaqU1@uni-berlin.de>
John Bokma (comp.lang.perl.misc) dijo...
> Abhinav wrote:
>
>> Hi
>>
>> I have a script where some chuncks of text are marked between xml-type
>> tags .
>>
>> I say 'xml-type' instead of xml as the tags are preceded with a comment
>> character "# " so that the script does not fail.
>
> Why not put the XML at the end, after __END__ and read it using <DATA>?
>
>> I need to be able to extract the data between tags (which can be
>> nested), and store it in a hash with each key being the tag itself and
>> the value, the data in between (it is multiline).
>
> Or open your script as a file, and read the #'s and throw away real
> comments (you can use ## for real ones for example), and parse the
> result. But I recommend __END__
>
>> The problem is that I initiially tried using Text::Balanced, but gave up
>> since ir was too demanding for this kind of work .. spanning across
>> multiple lines ..
>>
>> I am thinking of stripping the # from all tagged lines so that it
>> becomes an xml file, adding a root element (which was not present
>> before) , and then using an xml parser.
>
> Yup, good idea :-D.
>
>> My questions :
>> 1. Is the approach feasible, or is there som other simpler way to do it
>> .. (after all, TIMTOWTDI)
>
> use __END__
>
>> 2. If the above is the optimal solution, is there any parser/module
>> shipped along with the standard perl (5.8) distro .. ?
>
> Yes, but I like XML::Twig a lot ;-) Have a look at it.
>
> http://xmltwig.com/xmltwig/
>
> Other pointers:
>
> http://www.xml.com/pub/a/2000/04/05/feature/index.html
> http://perl-xml.sourceforge.net/faq/
You read each line without the preceding # and load it all in a scalar. Then
add it to the XMLin part of xmltwig. And get the parsed xml from XMLout.
Read the help file well since it has a lot of clauses in order to interpret
it well, but it is only trying and changing until you get the best result.
Then you have it all inside a hash reference (with array references inside).
--
.------------------. -.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.
| ___ _ _ _ _ | ALBERTO ADRIAN SCHIANO - ARGENTINA - 2004
|/ __/ | \ || | | | <ALETIA@2VIAS.COM.AR> # 34-34S 058-25W(z-3)
|||_< \| || ' | | +------------+------------------------------
|`____/|_\_|`___' | LINUX COUNTER: 240 133 ~ machine : 119 401
| _ _ _ __ _ | +------------+----------+-------------------
|| | | \ |\ \/ | AMD Athlon 6 |RAM 512Mb.|krnl.: 2.6.3-10mdk
|| |_ | | \ \ | i586-mandrake-linux-gnu |MDK 9.2 - KDE 3.13
||___||_\_|_/\_\ | +-----------------------+-------------------
| __ __ ___ _ _ | Maxtor #4D040H2 32Gb. |DISPLAY_VGA SiS 630
|| \ \| . \| / | ------------------------+--+----------------
|| || | || \ | PCI Audio snd-trident 7018 | ViewSonic E771
||_|_|_||___/|_\_ | ---------------------------+----------------
| | http://perlmonks.org/index.pl?node_id=245320
'------------------' -.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.
------------------------------
Date: Fri, 28 May 2004 12:13:30 +0530
From: Abhinav <matrix_calling@yahoo.dot.com>
Subject: Re: xml type parser in the standard perl installation ?
Message-Id: <2jBtc.48$wQ3.62@news.oracle.com>
John Bokma wrote:
> Abhinav wrote:
>
>> Hi
>>
>> I have a script where some chuncks of text are marked between xml-type
>> tags .
>>
>> I say 'xml-type' instead of xml as the tags are preceded with a
>> comment character "# " so that the script does not fail.
>
>
> Why not put the XML at the end, after __END__ and read it using <DATA>?
>
Hi John ,
Thanks ! I was not clear when I said "I have a script" . I actually
meant that I have a Winrunner script, Not Perl script, in which i wanted
to put these tags. (So as to extract info from the Winrunner script,
using a perl script :) )
>> I need to be able to extract the data between tags (which can be
>> nested), and store it in a hash with each key being the tag itself and
>> the value, the data in between (it is multiline).
>
>
> Or open your script as a file, and read the #'s and throw away real
> comments (you can use ## for real ones for example), and parse the
> result. But I recommend __END__
>
>> The problem is that I initiially tried using Text::Balanced, but gave
>> up since ir was too demanding for this kind of work .. spanning across
>> multiple lines ..
>>
>> I am thinking of stripping the # from all tagged lines so that it
>> becomes an xml file, adding a root element (which was not present
>> before) , and then using an xml parser.
>
>
> Yup, good idea :-D.
>
>> My questions :
>> 1. Is the approach feasible, or is there som other simpler way to do
>> it .. (after all, TIMTOWTDI)
>
>
> use __END__
>
>> 2. If the above is the optimal solution, is there any parser/module
>> shipped along with the standard perl (5.8) distro .. ?
>
>
> Yes, but I like XML::Twig a lot ;-) Have a look at it.
>
> http://xmltwig.com/xmltwig/
>
> Other pointers:
>
> http://www.xml.com/pub/a/2000/04/05/feature/index.html
> http://perl-xml.sourceforge.net/faq/
Thanks .. that gives me enough to do for now :) Anyway, good to know
that the approach I want to use fnids accepteance :)
Regards
AB
------------------------------
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 6619
***************************************