[24434] in Perl-Users-Digest
Perl-Users Digest, Issue: 6618 Volume: 10
daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Thu May 27 21:05:45 2004
Date: Thu, 27 May 2004 18:05:06 -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 Thu, 27 May 2004 Volume: 10 Number: 6618
Today's topics:
Re: (repost) Math problem - converting between arbitrar (Jay Tilton)
Re: Anonymous <net.weathersongATnemo>
Re: Anonymous <emschwar@pobox.com>
Re: Anonymous <usenet@morrow.me.uk>
Beginner need help on perl issues <mikael.petterson@era.ericsson.se>
Re: Beginner need help on perl issues (Greg Bacon)
Re: Beginner need help on perl issues <noreply@gunnar.cc>
Re: Beginner need help on perl issues <emschwar@pobox.com>
Re: How to Pattern match the keys in a hash <tore@aursand.no>
Re: How to Pattern match the keys in a hash <usenet@morrow.me.uk>
Re: How to pattern match using capture to create a hash <1usa@llenroc.ude>
Re: How to pattern match using capture to create a hash (Greg Bacon)
Re: Listing files sorted by creation time <krahnj@acm.org>
Re: Listing files sorted by creation time <krahnj@acm.org>
Re: Listing files sorted by creation time <ebohlman@omsdev.com>
Re: Making sure that we're dealing with an array (refer <tore@aursand.no>
Obtaining matched (sub)string (Michael T. Davis)
Re: Obtaining matched (sub)string <noreply@gunnar.cc>
perl expect->spawn cannot find the executable file. (Swamy)
Regular Expressions <johnb@NixSpaMiprimus.com.au.com.au>
Why is this upload script not working (Mark Constant)
Re: xml type parser in the standard perl installation ? <postmaster@castleamber.com>
Digest Administrivia (Last modified: 6 Apr 01) (Perl-Users-Digest Admin)
----------------------------------------------------------------------
Date: Fri, 28 May 2004 00:22:02 GMT
From: tiltonj@erols.com (Jay Tilton)
Subject: Re: (repost) Math problem - converting between arbitrary bases in perl - help!
Message-Id: <40b683f1.279178978@news.erols.com>
" ! aaa" <ToGroun@NotTo.me> wrote:
: 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 '-').
Look at Math::BaseCalc.
use Math::BaseCalc;
my $b03 = Math::BaseCalc ->new(digits => [0..2]);
my $b37 = Math::BaseCalc ->new(digits => ['a'..'z',0..9,'-']);
print $b37 ->to_base( $b03 ->from_base( $some_trinary_number ) );
------------------------------
Date: Fri, 28 May 2004 00:18:36 GMT
From: David Frauzel <net.weathersongATnemo>
Subject: Re: Anonymous
Message-Id: <4aa9fb3e10752e753e13146ea60f54a6@news.teranews.com>
Tad McClellan <tadmc@augustmail.com> wrote in
news:slrncb7uoj.rq.tadmc@magna.augustmail.com:
> You never _must_ use an array without a name, but it is often
> convenient, particularly if you do not need to make use of
> the name.
Thanks. :) One follow-up question:
These two statements have different behavior:
@foo = @bar;
@foo = ['foo', 'bar'];
The second statement returns a reference, not a copy. Is this intentional,
as another kind of convenience? (Since returning a copy of it would just be
wasteful.) And what happens to @foo when the anonymous array goes out of
scope? (Presumably at the end of the current block?)
------------------------------
Date: Thu, 27 May 2004 18:35:30 -0600
From: Eric Schwartz <emschwar@pobox.com>
Subject: Re: Anonymous
Message-Id: <etou0y12xt9.fsf@fc.hp.com>
David Frauzel <net.weathersongATnemo> writes:
> These two statements have different behavior:
>
> @foo = @bar;
> @foo = ['foo', 'bar'];
>
> The second statement returns a reference, not a copy. Is this intentional,
> as another kind of convenience?
It's intentional, because that's what [ list ] does-- return a
reference. If you want @foo to be ('foo', 'bar'), then you should
assign that to it, not ['foo', 'bar']. See perlreftut for more info on
references.
> (Since returning a copy of it would just be wasteful.)
Not if that's what you needed, which is why you have both () and [].
> And what happens to @foo when the anonymous array goes out of scope?
Nothing, presuming that @foo has wider scope than that. $foo[0] will
still contain a reference to an anonymous array.
-=Eric
--
Come to think of it, there are already a million monkeys on a million
typewriters, and Usenet is NOTHING like Shakespeare.
-- Blair Houghton.
------------------------------
Date: Fri, 28 May 2004 00:44:20 +0000 (UTC)
From: Ben Morrow <usenet@morrow.me.uk>
Subject: Re: Anonymous
Message-Id: <c96214$a0f$1@wisteria.csv.warwick.ac.uk>
Quoth David Frauzel <net.weathersongATnemo>:
> Tad McClellan <tadmc@augustmail.com> wrote in
> news:slrncb7uoj.rq.tadmc@magna.augustmail.com:
>
> > You never _must_ use an array without a name, but it is often
> > convenient, particularly if you do not need to make use of
> > the name.
>
> Thanks. :) One follow-up question:
>
> These two statements have different behavior:
>
> @foo = @bar;
> @foo = ['foo', 'bar'];
Note that this sets $foo[0] to the reference. This is not at all the
same as
@foo = ('foo', 'bar');
> The second statement returns a reference, not a copy. Is this intentional,
> as another kind of convenience? (Since returning a copy of it would just be
> wasteful.)
No, it is intentional as that is what you asked for. Compare:
my $foo = ['foo', 'bar'];
my @foo = ('foo', 'bar');
> And what happens to @foo when the anonymous array goes out of
> scope? (Presumably at the end of the current block?)
You are confusing a variable and its name. A name has a scope; the
variable itself is refcounted. The variable is not destroyed until all
refs and all names are gone. So:
{
my $foo;
{
my $bar = [];
$foo = [];
}
# The name $bar goes out of scope here.
# The scalar variable it refers to is destroyed, as there are no
# other refs.
# The anon array it held a reference to is destroyed, as it has no
# name and no refs.
# The name $foo is still in scope, so the variable still exists.
# The scalar named by $foo contains a reference to an anon array, so
# that anon array still exists, as well.
}
# The name $foo goes out of scope here. The scalar variable and anon
# array are destroyed as for $bar.
Does this make things clearer?
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: Thu, 27 May 2004 12:59:13 +0200
From: Petterson Mikael <mikael.petterson@era.ericsson.se>
Subject: Beginner need help on perl issues
Message-Id: <40B5CA01.DCE45EE4@era.ericsson.se>
Hi,
What is the meaning of
my ($common,$local) = @_; in sub?
sub insert_or_update
{
my ($common,$local) = @_;
....
}
Also I have a regular expression looking like the following ( see
below).
I does it on a file containing key=value.
Can anyone explain what is done?
foreach (@common_lines)
{
if (($common_key,$common_value) = /^\s*([^=#]+?)\s*=\s*(.*)$/)
{
$common_map{"$common_key"} = "$common_value";
}
}
All hints appreciated.
BR
//Mikael
------------------------------
Date: Thu, 27 May 2004 22:29:21 -0000
From: gbacon@hiwaay.net (Greg Bacon)
Subject: Re: Beginner need help on perl issues
Message-Id: <10bcqu1j6umpbe2@corp.supernews.com>
In article <40B5CA01.DCE45EE4@era.ericsson.se>,
Petterson Mikael <mikael.petterson@nospam.se> wrote:
: What is the meaning of
:
: my ($common,$local) = @_; in sub?
Try it out. Consider the following code:
@_ = ('apples', 'oranges', 'bananas');
my ($common,$local) = @_;
print "common = $common\n",
"local = $local\n";
It produces the following output:
common = apples
local = oranges
As you can see, it copies the first two items off the @_ array.
Read the perldata manpage. This is documented in the section on
lists.
: Also I have a regular expression looking like the following ( see
: below). I does it on a file containing key=value.
: Can anyone explain what is done?
:
: foreach (@common_lines)
: {
: if (($common_key,$common_value) = /^\s*([^=#]+?)\s*=\s*(.*)$/)
: {
: $common_map{"$common_key"} = "$common_value";
: }
: }
Piece by piece:
^ - "At the beginning of the line..."
\s* - "...optional whitespace followed by..."
( - "...(and remember what matches here)..."
[^=#]+? - "...match one or more chars that aren't = or #..."
) - "...return this value..."
\s* - "...followed by optional whitespace..."
= - "...followed by an equals sign..."
\s* - "...followed by optional whitespace..."
( - "...(and remember what matches here)...
.* - "...whatever's left on the line..."
) - "...also return this value if we match..."
$ - "...followed by end of line."
On a match, the regular expression match operator, i.e., /.../,
returns the portions of the input text -- in this case, each element of
@common_lines in turn -- that matched the parenthesized subexpressions,
i.e., ([^=#]+?) and (.*) in this case.
Hope this helps,
Greg
--
Calculating the cost per MW received is left as an exercise for those
readers who know how. I don't think that includes you, or you wouldn't
have posted this.
-- Paul Robichaux in hsv.general
------------------------------
Date: Fri, 28 May 2004 00:28:49 +0200
From: Gunnar Hjalmarsson <noreply@gunnar.cc>
Subject: Re: Beginner need help on perl issues
Message-Id: <2hn8i8Ff2n67U1@uni-berlin.de>
Petterson Mikael wrote:
> What is the meaning of
>
> my ($common,$local) = @_; in sub?
>
> sub insert_or_update
> {
> my ($common,$local) = @_;
If you pass arguments to that sub by calling it like:
insert_or_update('arg1', 'arg2');
those arguments will become elements in the @_ array. I leave it to
you to guess the rest. ;-)
Suggested reading:
http://www.perldoc.com/perl5.8.4/pod/perlintro.html
http://www.perldoc.com/perl5.8.4/pod/perlsub.html
> Also I have a regular expression looking like the following ( see
> below).
> I does it on a file containing key=value.
> Can anyone explain what is done?
>
> foreach (@common_lines)
> {
> if (($common_key,$common_value) = /^\s*([^=#]+?)\s*=\s*(.*)$/)
> {
> $common_map{"$common_key"} = "$common_value";
> }
> }
It populates the hash %common_map with the key/value pairs.
Note that throwing out random questions like those, without showing
that you have made own efforts to find the answers, is not a
reasonable way to learn basic Perl. If you want to learn Perl, this is
a suitable starting point:
http://learn.perl.org/
And before posting to this newsgroup again, please study the posting
guidelines:
http://mail.augustmail.com/~tadmc/clpmisc/clpmisc_guidelines.html
Good luck!
--
Gunnar Hjalmarsson
Email: http://www.gunnar.cc/cgi-bin/contact.pl
------------------------------
Date: Thu, 27 May 2004 16:58:56 -0600
From: Eric Schwartz <emschwar@pobox.com>
Subject: Re: Beginner need help on perl issues
Message-Id: <eto7jux4gun.fsf@fc.hp.com>
Petterson Mikael <mikael.petterson@era.ericsson.se> writes:
Please put the subject of your post in the Subject: of your post.
Think of it this way: suppose you were searching for answers to your
questions in some newsgroup archive like groups.google.com. Would you
be able to figure out that this post was relevant, just by looking at
the Subject: line?
> What is the meaning of
>
> my ($common,$local) = @_; in sub?
Read 'perlintro' (with 'perldoc perlintro'). You can probably stop
doing everything else you're doing with Perl until you finish that,
it's that basic.
> Also I have a regular expression looking like the following ( see
> below).
> I does it on a file containing key=value.
> Can anyone explain what is done?
You'll want to read 'perlretut' (for "Perl Regex Tutorial") with
'perldoc perlretut'. This one's pretty simple, so I'll help you
decode it, but you'll really want to read perlretut
> foreach (@common_lines)
> {
> if (($common_key,$common_value) = /^\s*([^=#]+?)\s*=\s*(.*)$/)
Let's write it out the long way:
if (my ($common_key,$common_value) = /^\s*
This says there is optional whitespace at the beginning of the line. \s
matches any white space character, and * means there are zero or more of them.
If you wanted to guarantee there was at least one whitespace character here,
then you'd use + instead of *
([^=#]+?)
Followed by a number of characters that are not = or #. The parens put
these matched characters into $1 (because it's the first set of parens)
\s*
Followed by optional whitespace
=
a literal = character
\s*
more optional whitespace
(.*)
and capture everything after the whitespace into $2 (since it's the
second set of parens
$/x))
and $ matches the end of the string. I added /x because /x says to
ignore whitespace in the regex, and you could just rip out my comments
and have an exact equivalent to the regex you quoted.
Now, the bits on the left hand side, as written, are:
($common_key, $common_value) = /...regex.../;
You should always put 'use warnings;' and 'use strict;' at the top of
all your Perl programs. This requires you to declare your variables,
so you'd write instead,
my ($common_key, $common_value) = /...regex.../;
The fact that the variables $common_key and $common_value are in
parentheses means that they are in list context. Perl does different
things sometimes depending on if an operator like // is in scalar
context or list context.
Now, I don't want to give away all the fun, and besides you could
probably stand to learn the practice of looking up the docs on your
own, so why don't you search perlretut for what happens when // is
evaluated in list context, and let us know what you find out? You
should be able to find the documentation easily, but if you can't
understand it, post back, and we'll help you work through it.
-=Eric
--
Come to think of it, there are already a million monkeys on a million
typewriters, and Usenet is NOTHING like Shakespeare.
-- Blair Houghton.
------------------------------
Date: Fri, 28 May 2004 01:20:59 +0200
From: Tore Aursand <tore@aursand.no>
Subject: Re: How to Pattern match the keys in a hash
Message-Id: <pan.2004.05.27.23.14.45.91559@aursand.no>
On Thu, 27 May 2004 11:56:53 -0700, Ash wrote:
> #!C:/Program~1/Perl/bin
use strict;
use warnings;
> $filea = "D:/scripts/super/wks_name_login.txt"; -->The file with entries
my $filea = 'D:/scripts/super/wks_name_login.txt';
> open (A, "<$filea") or die "$!\n";
open( A, '<', $filea ) or die "$!\n";
> while(<A>) {
>
> chomp;
>
> /^\s(\w-\w-\w-\d{3})\s* (.*)$/;
> $fields{$1} = $2;
> }
while ( <A> ) {
chomp;
my ( $machine, $user ) = split( /\s+/, $_, 2 );
if ( $machine =~ /-\d{3}$/ ) {
$fields{$machine} = $user;
}
}
--
Tore Aursand <tore@aursand.no>
"Computer language design is just like a stroll in the park. Jurassic
Park, that is." (Larry Wall)
------------------------------
Date: Thu, 27 May 2004 23:24:25 +0000 (UTC)
From: Ben Morrow <usenet@morrow.me.uk>
Subject: Re: How to Pattern match the keys in a hash
Message-Id: <c95tb9$7vf$1@wisteria.csv.warwick.ac.uk>
Quoth Tore Aursand <tore@aursand.no>:
> On Thu, 27 May 2004 11:56:53 -0700, Ash wrote:
>
> > open (A, "<$filea") or die "$!\n";
>
> open( A, '<', $filea ) or die "$!\n";
open my $A, '<', $filea or die "can't open $filea: $!";
Ben
--
don't get my sympathy hanging out the 15th floor. you've changed the locks 3
times, he still comes reeling though the door, and soon he'll get to you, teach
you how to get to purest hell. you do it to yourself and that's what really
hurts is you do it to yourself just you, you and noone else ** ben@morrow.me.uk
------------------------------
Date: 27 May 2004 22:06:59 GMT
From: "A. Sinan Unur" <1usa@llenroc.ude>
Subject: Re: How to pattern match using capture to create a hash
Message-Id: <Xns94F6B84A916C1asu1cornelledu@132.236.56.8>
Ash <ashutosh.jog@pdf.com> wrote in
news:10bclvrrhggfn01@corp.supernews.com:
> Great suggestions. It worked.
>
> Thanks.
<SNIP>
You can return the favor by reading the posting guidelines for this group
and following them. For example, you should always have:
use strict;
use warnings;
in your script.
And avoid top-posting.
--
A. Sinan Unur
1usa@llenroc.ude (reverse each component for email address)
------------------------------
Date: Thu, 27 May 2004 22:16:54 -0000
From: gbacon@hiwaay.net (Greg Bacon)
Subject: Re: How to pattern match using capture to create a hash
Message-Id: <10bcq6mtd8fg145@corp.supernews.com>
In article <10bclvrrhggfn01@corp.supernews.com>,
Ash <ashutosh.jog@pdf.com> wrote:
: Great suggestions. It worked.
:
: Thanks.
Glad to help.
Greg
--
The welfare state is not really about the welfare of the masses. It
is about the egos of the elites.
-- Walter Williams
------------------------------
Date: Thu, 27 May 2004 23:22:39 GMT
From: "John W. Krahn" <krahnj@acm.org>
Subject: Re: Listing files sorted by creation time
Message-Id: <40B6783F.461E7BA6@acm.org>
Yash wrote:
>
> I would like to do something with every text file from a directory,
> with the latest created file taken first.
> What is the best way to do this. I am looking for something like:
>
> for my $file ( <something> glob("/mydir/*.txt") )
> {
> #my code
> }
>
> The glob will create an array of filenames. How do I make sure the
> list comes in time order , latest fist?
Of course *nix doesn't store the creation time anywhere but you can use
the time that the file was last maodified:
for my $file ( map $_->[1],
sort { $a->[0] <=> $b->[0] }
map [ -M, $_ ],
glob '/mydir/*.txt' )
{
#my code
}
John
--
use Perl;
program
fulfillment
------------------------------
Date: Thu, 27 May 2004 23:26:53 GMT
From: "John W. Krahn" <krahnj@acm.org>
Subject: Re: Listing files sorted by creation time
Message-Id: <40B6793D.DDFF2C95@acm.org>
Jim Gibson wrote:
>
> In article <5a373b1d.0405270647.239815a0@posting.google.com>, Yash
> <yashgt@yahoo.com> wrote:
> >
> > I would like to do something with every text file from a directory,
> > with the latest created file taken first.
> > What is the best way to do this. I am looking for something like:
> >
> > for my $file ( <something> glob("/mydir/*.txt") )
> > {
> > #my code
> > }
> >
> > The glob will create an array of filenames. How do I make sure the
> > list comes in time order , latest fist?
>
> On unix, you can do:
>
> my @files = `cd /mydir;ls -t *.txt`;
^^^^^^^^^
You are changing the directory in a different process which means that
the list of file names returned will not be available from the current
directory and you didn't chomp the list so every file name will have a
newline at the end.
> for my $file ( @files ) {
> # your code
> }
John
--
use Perl;
program
fulfillment
------------------------------
Date: 28 May 2004 00:46:26 GMT
From: Eric Bohlman <ebohlman@omsdev.com>
Subject: Re: Listing files sorted by creation time
Message-Id: <Xns94F6C9D739C48ebohlmanomsdevcom@130.133.1.4>
"John W. Krahn" <krahnj@acm.org> wrote in news:40B6783F.461E7BA6@acm.org:
> Of course *nix doesn't store the creation time anywhere but you can use
> the time that the file was last maodified:
Would that be the date of the file's last Cultural Revolution?
------------------------------
Date: Fri, 28 May 2004 01:20:59 +0200
From: Tore Aursand <tore@aursand.no>
Subject: Re: Making sure that we're dealing with an array (reference)
Message-Id: <pan.2004.05.27.17.58.13.46669@aursand.no>
On Thu, 27 May 2004 18:05:33 +0100, Brian McCauley wrote:
>> One thing that happens quite often when I program in Perl, is that I need
>> to initialise a variable to be an array reference.
>>
>> $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 know $paths can never be an reference to anything but an array
> (and often you do know this) it simplifies to:
>
> $paths = ref($paths) ? $paths : [ $paths ];
That's correct. I also have in mind that I don't pass complex structures
(or blessed objects) to this function. My current test scenario is like
this:
my @array = qw( a b c );
my $ref1 = as_arrayref( @array ); # [ 'a', 'b', 'c' ]
my $ref2 = as_arrayref( \@array ); # [ 'a', 'b', 'c' ]
my $ref3 = as_arrayref( 'a b c' ); # [ 'a b c' ]
Thus, it seems to work as expected;
sub as_arrayref {
my @data = @_;
if ( @data > 1 ) {
return \@data;
}
else {
return ( ref($data[0]) eq 'ARRAY' ) ? $data[0] : [ $data[0] ];
}
}
It sure doesn't account for everything, especially when dealing with
complex structures, but that isn't necessary in my case. Anyone have a
better way?
If not - on towards 'as_hashref'. :-)
--
Tore Aursand <tore@aursand.no>
"People that think logically are a nice contrast to the real world."
(Matt Biershbach)
------------------------------
Date: 27 May 2004 23:25:23 GMT
From: DAVISM@er6.eng.ohio-state.edu (Michael T. Davis)
Subject: Obtaining matched (sub)string
Message-Id: <c95td3$kjn$1@charm.magnus.acs.ohio-state.edu>
When using m//, is it possible to obtain the (sub)string of the
target which actually matched the regex? For example, if the target is
"Get your viagra here" and the regex is "(cialis|viagra|xanax)", is there
a way to indicate that the match was "viagra"?
Thanks,
Mike
--
Michael T. Davis | Systems Specialist: ChE,MSE
E-mail: davism@er6.eng.ohio-state.edu | Departmental Networking/Computing
-or- DAVISM+@osu.edu | The Ohio State University
http://www.er6.eng.ohio-state.edu/~davism/ | 197 Watts, (614) 292-6928
------------------------------
Date: Fri, 28 May 2004 01:35:47 +0200
From: Gunnar Hjalmarsson <noreply@gunnar.cc>
Subject: Re: Obtaining matched (sub)string
Message-Id: <2hncfsFdhbnmU1@uni-berlin.de>
Michael T. Davis wrote:
> When using m//, is it possible to obtain the (sub)string of the
> target which actually matched the regex? For example, if the
> target is "Get your viagra here" and the regex is
> "(cialis|viagra|xanax)", is there a way to indicate that the match
> was "viagra"?
Err.. Yes. By examining the content of $1.
http://www.perldoc.com/perl5.8.4/pod/perlretut.html
(Are there any spam crap any longer that spells out "viagra" in
cleartext?)
--
Gunnar Hjalmarsson
Email: http://www.gunnar.cc/cgi-bin/contact.pl
------------------------------
Date: 27 May 2004 16:46:24 -0700
From: swamyb@hotmail.com (Swamy)
Subject: perl expect->spawn cannot find the executable file.
Message-Id: <1aaaeaf0.0405271546.4d9be5ea@posting.google.com>
I have written a perl/expect program to automate the interactive shell
program.
The shell program needs to be run in local directory. That's fine. I
have done the following..
$exp->expect(30,"-re", $prompt);
$exp->send("cd <dir path>");
$exp->expect(30,"-re", $prompt);
$exp->send("pwd\n");
$exp->expect(30,"-re", $prompt);
$exp->spawn("install.sh");
^^^^^^^^
or $exp->spawn("./install.sh);
If I do this, I get an error saying install.sh is not found and
further expect command complains unidentified variable error or
something..
If I do
$exp->spawn("<dir path>/install.sh"); it works, but
installation fails.
The installation script looks for certain files locally and I have to
run this script from its. current directory. Can anybody tell me how
to make spawn work?
thanks
Swamy
------------------------------
Date: Fri, 28 May 2004 11:02:32 +1000
From: "John Baro" <johnb@NixSpaMiprimus.com.au.com.au>
Subject: Regular Expressions
Message-Id: <2hnh9vFf955hU1@uni-berlin.de>
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
------------------------------
Date: 27 May 2004 17:51:59 -0700
From: constants@mix-net.net (Mark Constant)
Subject: Why is this upload script not working
Message-Id: <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.
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");
binmode(OUTFILE);
while (my $bytesread = read($file, $buffer, 1024)) {
print OUTFILE $buffer;
}
close(OUTFILE);
print "File saved\n";
}
$q->end_html;
sub dienice {
my($msg) = @_;
print "<h2>Error</h2>\n";
print $msg;
exit;
}
------------------------------
Date: Thu, 27 May 2004 18:59:05 -0500
From: John Bokma <postmaster@castleamber.com>
Subject: Re: xml type parser in the standard perl installation ?
Message-Id: <40b680ca$0$213$58c7af7e@news.kabelfoon.nl>
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/
--
John MexIT: http://johnbokma.com/mexit/
personal page: http://johnbokma.com/
Experienced Perl programmer available: http://castleamber.com/
------------------------------
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 6618
***************************************