[21803] in Perl-Users-Digest
Perl-Users Digest, Issue: 4007 Volume: 10
daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Mon Oct 21 18:05:52 2002
Date: Mon, 21 Oct 2002 15:05:12 -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, 21 Oct 2002 Volume: 10 Number: 4007
Today's topics:
[REPOST] Need advice on a project (wrt to tie'ing to a <bik.mido@tiscalinet.it>
Assigning one symbol table to another one <bobesch@letras.net>
Calling Subroutines (KP)
Re: Calling Subroutines <tassilo.parseval@post.rwth-aachen.de>
cann't run on perl 5.005_03 (Terry)
Re: cann't run on perl 5.005_03 <usenet@tinita.de>
Re: cyrpt() and other questions.... <garry@ifr.zvolve.net>
Re: DBI module INSERT command problem <dgardiner@houston.rr.com>
Difference in regular expression replacement between 5. (J. Gilbert)
eval, I think <bmetcalf@nortelnetworks.com>
Re: eval, I think <tassilo.parseval@post.rwth-aachen.de>
Re: eval, I think <uri@stemsystems.com>
Re: exec command (Theodore)
Re: exec command <garry@ifr.zvolve.net>
format to output <nospam@nospam.org>
how to igore the comments line in files? (miao mao)
How to use flock properly? (D. Alvarado)
How to use script get login page? <shu.wang2@verizon.net>
lost - map { "$_:\t$h->{$_}[0]\n"} keys %$h <g-preston1@ti.com>
new error <g-preston1@ti.com>
opendir/readdir can't handle french characters: What am (Jean Gagnon)
Re: opendir/readdir can't handle french characters: Wha <krahnj@acm.org>
parsing XML to FrameMaker: newline troubles in regex (benrog)
Re: parsing XML to FrameMaker: newline troubles in rege <cpryce@pryce.net>
Re: parsing XML to FrameMaker: newline troubles in rege (Tad McClellan)
Question about hash entries with two keys (J. Romano)
Re: Question about hash entries with two keys (Jay Tilton)
Re: Question about hash entries with two keys <tassilo.parseval@post.rwth-aachen.de>
Re: Question about hash entries with two keys <uri@stemsystems.com>
Re: Stopping IIS website <neilmcse@hotmail.com>
Digest Administrivia (Last modified: 6 Apr 01) (Perl-Users-Digest Admin)
----------------------------------------------------------------------
Date: Mon, 21 Oct 2002 22:41:04 +0200
From: Michele Dondi <bik.mido@tiscalinet.it>
Subject: [REPOST] Need advice on a project (wrt to tie'ing to a file and general strategy)
Message-Id: <1le7rucfpapl8bl9g8npvht0n5tir6557k@4ax.com>
Last week I posted the article pasted hereafter. Since I haven't
received much feedback, I'm posting it again. Sorry for any
disturbance this might cause...
### OP
A few years ago I wrote a shell script to find duplicates in a
directory tree and remove them (keeping only the 1st one wrt
alphabetical order).
My script, though gross and primitive, has worked reliably for me for
a long time, but now I'd like to rewrite it in perl with some
enhancements too, one difference being that it should run also (and
possibly, mainly) on Windows.
Let me explain how it did work first. Necessary conditions for two
files to be identical are
(i) They have the same size,
(ii) They have the (a) same checksum.
I assume that (i) AND (ii) are also a sufficient condition, even if
that's simply not true, that is, I don't mind extremely rare cases of
different files having both same size and checksum.
My script worked by calculating (how is a detail) the file sizes of
files in the directory tree, sorting by the sizes and comparing the
checksums of files with the same size. To be precise, fwim, I used the
md5sum program to calculate checksums.
I used the above strategy because calculating a checksum is always
more time-consuming than printing a file size.
So, the first question regards how to calculate checksums with perl:
do I have to resort to external programs (thus, possibly, having to
use a Windows port of a *nix one for compatibility) or is there a
(recommended) module suitable for this task?
Also, I know (more than) one way to make such a program, but an
important consideration to take into account is that now I should run
it on huge (for me) "data sets" (that is of the size of 10^5 files).
I know from FAQs, etc. that a solution is to tie to a file (whatever I
will use: array, hash...), but there are many modules designed for
that. Which one do you recommend? I'd prefer a KISS solution, that is,
I know that some of them use some sort of database libraries
transparently, but it seems to me an overhead.
In case I decide to use a DB-oriented module, are there any
portability issues wrt the abovementioned libraries (e.g. are they
available and work reliably on "all" platforms?).
Also, I would like to cache the data relative to size/checksums when
they are calculated, so to "include them on the list" when running the
program subsequent times. Notice that I'm aware this strategy won't
catch all duplicates between one run and the other, but I'm sure it
would be nevertheless an enhancement for my purposes...
### END OF OP
For completeness sake I paste here also my answer to one reply I
actually got:
### ANSWER
On Fri, 18 Oct 2002 22:41:39 -0700, "Tan Nguyen" <nospam@nospam.com>
wrote:
>As pointed out in the previous post, there's Digest::MD5 on CPAN for your
>need. However, this beast is very slow (not because of Perl, it's the
>algorithm), but good to bring the probability of collision of two distinct
>file close to zero.
Don't laugh, but I seem to remember (not sure myself) that actually I
had chosen md5sum for some "ease of use" due to its fixed-length
output wrt, e.g. 'cksum'.
>If you don't mind the chance of two distinct files with the same filename
>and checksum, and like to speed up your checksum computation significantly,
>you might consider using CRC32. Correct me if I'm wrong, the collision
>probability of CRC32 is 2^(-32) which is approximately one out of 4 billion
>trials. Might be good enough for you application.
Indeed it would be good enough for my application. Now is there a
CRC32 module for perl? (OK, I'll search CPAN...)
>If you like to keep things in memory, you might want to give an estimate on
>how much memory you need to hold the whole thing. This varies widely
>depending on the average length of the filenames, average length of string
>of size of files and the number of files. (I assume that you'd like to keep
>a hash keyed on the filesize with values being filenames), plus a fair
I was rather thinking of a hash keyed on the filesize with values
being references to arrays whose first entries are filenames and the
second ones, if present, are the cksums.
And I would keep those entries that have a checksum setting the
filename to "" (multiple ones thus collapsing into a single one) for
subsequent use, as I explained in the previous post.
>estimate = number of files * (average length of filenames + average length
>of string of size of files) + 30 % extra (Perl and checksum computation).
I have total sum of (length of filenames + length of string of size of
files) = 6334Kb in one particular test.
### END OF ANSWER
Michele
--
Liberta' va cercando, ch'e' si' cara,
Come sa chi per lei vita rifiuta.
[Dante Alighieri, Purg. I, 71-72]
I am my own country - United States Confederate of Me!
[Pennywise, "My own country"]
------------------------------
Date: 21 Oct 2002 21:00:32 +0200
From: Bodo Schulze <bobesch@letras.net>
Subject: Assigning one symbol table to another one
Message-Id: <87y98r8vn3.fsf@letras.net>
Hi,
symbol tables being stored in hashes, I wonder why it is not possible
to assign them using the normal hash syntax
%hash1 = %hash2;
On the other hand, it is possible to do the assignment like this
@hash1{ keys %hash2 } = values %hash2;
Here is the example I tested:
#!/usr/bin/perl
use strict;
use warnings;
package pkg1;
use vars qw( $s @a %h );
$s = 'scalar-value';
@a = qw ( ar-val1 ar-val2 );
%h = ( key1 => 'val1', key2 => 'val2' );
print "\$pkg1::s : $pkg1::s\n";
print "\@pkg1::a : ";
print "$_ " for @pkg1::a; print "\n";
print "\%pkg1::h : ";
print "$_ => $pkg1::h{$_}, " for keys %pkg1::h; print "\n\n";
package pkg2;
use vars qw( $s @a %h );
### First test to assign symbol table of pkg1 to that of pkg2 - nope
#%pkg2:: = %pkg1:: ;
### Second test to assign symbol table of pkg1 to that of pkg2 - that's ok
@pkg2::{ keys %pkg1:: } = values %pkg1:: ;
### Print it
print "\$pkg2::s : $pkg2::s\n";
print "\@pkg2::a : ";
print "$_ " for @pkg2::a; print "\n";
print "\%pkg2::h : ";
print "$_ => $pkg2::h{$_}, " for keys %pkg2::h; print "\n";
__END__
The second test prints:
$pkg1::s : scalar-value
@pkg1::a : ar-val1 ar-val2
%pkg1::h : key1 => val1, key2 => val2,
$pkg2::s : scalar-value
@pkg2::a : ar-val1 ar-val2
%pkg2::h : key1 => val1, key2 => val2,
Any clues on that? Am I just stupidly missing a crucial point?
Best regards, Bodo
------------------------------
Date: 21 Oct 2002 13:53:15 -0700
From: snazystyl@hotmail.com (KP)
Subject: Calling Subroutines
Message-Id: <dc2b0830.0210211253.2b505aba@posting.google.com>
*** New to Perl ***
I saw this Signal code to help surpress error messages on these
boards. Works great. I try to make it a practice that I do not call
sub within subs since at times it makes it hard to read. How would I
go about putting the signal in a separate sub and call to it. I tried
once without any success.
sub GetExtensionsOnMachine
{
my $msg;
my $dir = $ENV{"SystemDrive"} . '\\';
local $SIG{__WARN__} = sub {
($msg) = shift;
print STDERR $msg unless ($msg =~ /^Can\'t opendir/);
};
}
------------------------------
Date: 21 Oct 2002 21:26:00 GMT
From: "Tassilo v. Parseval" <tassilo.parseval@post.rwth-aachen.de>
Subject: Re: Calling Subroutines
Message-Id: <ap1rd8$36a$1@nets3.rz.RWTH-Aachen.DE>
Also sprach KP:
> I saw this Signal code to help surpress error messages on these
> boards. Works great. I try to make it a practice that I do not call
> sub within subs since at times it makes it hard to read. How would I
> go about putting the signal in a separate sub and call to it. I tried
> once without any success.
>
> sub GetExtensionsOnMachine
> {
> my $msg;
> my $dir = $ENV{"SystemDrive"} . '\\';
>
> local $SIG{__WARN__} = sub {
> ($msg) = shift;
> print STDERR $msg unless ($msg =~ /^Can\'t opendir/);
> };
> }
You can't since %SIG is dynamically scoped.
Of course, you can always do this:
my $warn = sub {
my $msg = shift;
print STDERR $msg unless ($msg =~ /^Can\'t opendir/);
};
sub GetExtensionsOnMachine {
my $dir = $ENV{"SystemDrive"} . '\\';
local $SIG{__WARN__} = $warn;
...
}
But where is the difference anyway?
There is nothing to fear about subroutines within subroutines, as long
as you make them refer to a closure. Real subs wont nest properly, so
don't try this:
sub outer {
...
sub inner {
...
}
inner(@args);
}
Instead make the inner sub a reference:
sub outer {
...
my $inner = sub {
...
};
$inner->(@args);
}
Tassilo
--
$_=q!",}])(tsuJ[{@"tnirp}3..0}_$;//::niam/s~=)]3[))_$-3(rellac(=_$({
pam{rekcahbus;})(rekcah{lrePbus;})(lreP{rehtonabus;})(rehtona{tsuJbus!;
$_=reverse;s/sub/(reverse"bus").chr(32)/xge;tr~\n~~d;eval;
------------------------------
Date: Mon, 21 Oct 2002 16:37:58 -0400
From: "Donghui Zhuo (Terry)" <dhzhuo@uwaterloo.ca>
Subject: cann't run on perl 5.005_03
Message-Id: <3DB465A6.505@uwaterloo.ca>
Hi,
I have a perl script which runs smoothly on my box (perl 5.6.0 + linux),
however, when I try to run it on another box (perl 5.005_03 + solaris),
I got following error message:
"Can't locate warnings.pm in @INC (@INC contains:
/usr/perl5/5.00503/sun4-solaris /usr/perl5/5.00503
/usr/perl5/site_perl/5.005/sun4-solaris /usr/perl5/site_perl/5.005 .)"
My question is:
1) does perl 5.005_03 have warnings.pm?
2) where can I get warnings.pm?
Thanks!
------------------------------
Date: 21 Oct 2002 21:19:46 GMT
From: Tina Mueller <usenet@tinita.de>
Subject: Re: cann't run on perl 5.005_03
Message-Id: <ap1r1i$qrj5m$1@fu-berlin.de>
"Donghui Zhuo (Terry)" <dhzhuo@uwaterloo.ca> wrote:
> I have a perl script which runs smoothly on my box (perl 5.6.0 + linux),
> however, when I try to run it on another box (perl 5.005_03 + solaris),
> I got following error message:
> "Can't locate warnings.pm in @INC (@INC contains:
> /usr/perl5/5.00503/sun4-solaris /usr/perl5/5.00503
> /usr/perl5/site_perl/5.005/sun4-solaris /usr/perl5/site_perl/5.005 .)"
> My question is:
> 1) does perl 5.005_03 have warnings.pm?
nope.
> 2) where can I get warnings.pm?
remove "use warnings;" and add -w in the first line ("shebang").
it's a new feature for 5.6.0, and i actually don't know
if it's possible to add it to versions before.
perldoc perlrun
perldoc warnings
hth, tina
--
http://www.tinita.de/ \ enter__| |__the___ _ _ ___
http://Movies.tinita.de/ \ / _` / _ \/ _ \ '_(_-< of
http://PerlQuotes.tinita.de/ \ \ _,_\ __/\ __/_| /__/ perception
------------------------------
Date: Mon, 21 Oct 2002 21:48:31 GMT
From: Garry Williams <garry@ifr.zvolve.net>
Subject: Re: cyrpt() and other questions....
Message-Id: <slrnar8t9u.lsr.garry@zfw.zvolve.net>
On Mon, 21 Oct 2002 18:01:20 GMT, John W. Krahn <krahnj@acm.org> wrote:
> Tad McClellan wrote:
>>
>> (it is a Unix question, not a Perl question)
>>
>> The salt is used so password-guessers must make 65536 guesses
>> for each password they want to try.
>
> Since crypt(3) uses printable ASCII characters (according to my man
> page) it's not as high as 65536. :-)
4096, to be precise.
--
Garry Williams
------------------------------
Date: Mon, 21 Oct 2002 18:38:19 GMT
From: "Doug" <dgardiner@houston.rr.com>
Subject: Re: DBI module INSERT command problem
Message-Id: <vQXs9.183542$Fw2.5203791@twister.austin.rr.com>
"peter pilsl" <pilsl_use@goldfisch.at> wrote in message
news:3db41a47$1@e-post.inode.at...
> Doug wrote:
>
> >>
> > Now for the silly question. How do you access the direct console and
> > where
> > is it etc.? I've never heard of that.
> >
>
> Dont know what database you are using, but I'm sure it has some frontend
> where you can enter SQL-commands.
> In postgres - for this is what I use - its called psql. In MS-Access there
> is also some window where one can enter sql-commands, but I dont know how
> to access it ..
>
> Anyway: sorry if you felt offended. Only wanted to help debugging
> SQL-processing scripts
>
>
> peter
>
[snip]
No offense taken, I just never heard of it. There is a SQL view for
queries, but the syntax is quite a bit different than what is passed via DBI
module. A long time ago I found that. And I'm suing Access at the moment,
only cause I'm familar with the user side of it, so I can quickly build
tables for testing purposes.
------------------------------
Date: 21 Oct 2002 12:39:27 -0700
From: jcin617@aol.com (J. Gilbert)
Subject: Difference in regular expression replacement between 5.005_03 & 5.6.0
Message-Id: <7babd34f.0210211139.1c689477@posting.google.com>
$string = "owning_account_no_fk1"
With perl 5.005_03 the following syntax:
$string =~ s/\B[aeiou]//g;
is yielding: "ownng_ccnt_n_fk1".
However, in 5.6.0, the same syntax
is yielding: "ownng_ccunt_n_fk1".
Changing the syntax to:
$string =~ s/\B[aeiou]*//g;
yields the same string between
5.005_03 and 5.6.0: "ownng_ccnt_n_fk1".
My question is, is the difference in behavior for
the first syntax a result of a bug (or change) with
5.6.0? I'm willing to bet that the second syntax is
the more "correct" one, but I'd like to know why
the difference... any help would be great, thanks!
------------------------------
Date: 21 Oct 2002 21:20:04 GMT
From: Brandon Metcalf <bmetcalf@nortelnetworks.com>
Subject: eval, I think
Message-Id: <slrnar8rbt.201.bmetcalf@cash.rhiamet.com>
I'm trying to do something like
my $testop = $windows ? '-f' : '-l';
$ret = 1 if $testop $link;
But this obviously won't compile. I was thinking eval might help out
here, but I can't seem to put anything together that works.
I would rather have a pointer to the documentation where I can find a
solution instead of just the solution. That is, just a hint will do.
Thanks,
Brandon
--
Do not worry about your problems with mathematics, I assure you mine are
far greater.
--Albert Einstein
------------------------------
Date: 21 Oct 2002 21:34:35 GMT
From: "Tassilo v. Parseval" <tassilo.parseval@post.rwth-aachen.de>
Subject: Re: eval, I think
Message-Id: <ap1rtb$3j2$1@nets3.rz.RWTH-Aachen.DE>
Also sprach Brandon Metcalf:
> I'm trying to do something like
>
> my $testop = $windows ? '-f' : '-l';
>
> $ret = 1 if $testop $link;
>
> But this obviously won't compile. I was thinking eval might help out
> here, but I can't seem to put anything together that works.
>
> I would rather have a pointer to the documentation where I can find a
> solution instead of just the solution. That is, just a hint will do.
The obvious place would be 'perldoc -f eval'.
eval() is really two functions in one so make sure you use the right one
under the right circumstances.
Block-eval (as in 'eval { ... }') takes proper Perl-code, compiles it at
*compile-time* (and will also give errors and warnings if the code
contained was improper). It is used to trap errors, that is, when you
don't yet know whether the code will run succesfully or not:
chomp (my $div = <STDIN>);
my $result = eval { 1 / $div };
if ($@) {
print "Did not work: $@";
}
String-eval on the other hand is what you want here. You build a string
which is later interpreted as Perl-code. This happens at *run-time* of
course since the string to be evaled does not yet exist at compile time
as opposed to block-eval:
my $code = <STDIN>;
eval "for (1 .. 10) { $code }";
if ($@) {
# likeweise
}
This should run the Perl-code contained in $code ten times.
Tassilo
--
$_=q!",}])(tsuJ[{@"tnirp}3..0}_$;//::niam/s~=)]3[))_$-3(rellac(=_$({
pam{rekcahbus;})(rekcah{lrePbus;})(lreP{rehtonabus;})(rehtona{tsuJbus!;
$_=reverse;s/sub/(reverse"bus").chr(32)/xge;tr~\n~~d;eval;
------------------------------
Date: Mon, 21 Oct 2002 21:39:29 GMT
From: Uri Guttman <uri@stemsystems.com>
Subject: Re: eval, I think
Message-Id: <x7lm4rjwtq.fsf@mail.sysarch.com>
>>>>> "BM" == Brandon Metcalf <bmetcalf@nortelnetworks.com> writes:
BM> I'm trying to do something like
BM> my $testop = $windows ? '-f' : '-l';
BM> $ret = 1 if $testop $link;
BM> I would rather have a pointer to the documentation where I can find a
BM> solution instead of just the solution. That is, just a hint will do.
someone else mentioned eval which is overkill IMO.
use the ?: op but return the full -X expressions. makes the whole
thing one line:
$ret = 1 if ( $windows ? -f $link : -l $link ) ;
that might not need parens as i haven't tested it.
and even simpler since -f and -l return booleans is to drop the 1 and
if:
$ret = $windows ? -f $link : -l $link ;
uri
--
Uri Guttman ------ uri@stemsystems.com -------- http://www.stemsystems.com
----- Stem and Perl Development, Systems Architecture, Design and Coding ----
Search or Offer Perl Jobs ---------------------------- http://jobs.perl.org
------------------------------
Date: 21 Oct 2002 12:36:51 -0700
From: crandall5138@msn.com (Theodore)
Subject: Re: exec command
Message-Id: <d98ac6f5.0210211136.1a0ff0d5@posting.google.com>
Bart Lateur <bart.lateur@pandora.be> wrote in message news:<oae7rus10u72e6q8jckn90j8gdqeuo352d@4ax.com>...
> Here you only have two parts. Try
>
> exec "mozilla", "-remote", "openURL($URL, new-tab)";
>
> or
>
> exec "mozilla -remote \"openURL($URL, new-tab)\"";
I tried the 2nd one and it worked! Thanks for all the help everyone.
------------------------------
Date: Mon, 21 Oct 2002 21:56:20 GMT
From: Garry Williams <garry@ifr.zvolve.net>
Subject: Re: exec command
Message-Id: <slrnar8toj.lsr.garry@zfw.zvolve.net>
On Mon, 21 Oct 2002 08:50:23 GMT, Bart Lateur <bart.lateur@pandora.be>
wrote:
> Theodore wrote:
>>I am trying to write a perl script to open new links in a new tab as
>>opposed to a new window.
>>
>>The command
>>mozilla -remote "openURL(URL, new-tab)"
>>does it fine.
>
> That looks like a 3 part command line to me.
>
>>I have
>>
>>$prog = "/usr/bin/mozilla";
>>
>>$arg = "-remote \"openURL(" . $URL . ", new-tab)\"";
>>
>>exec $prog, $arg;
>
> Here you only have two parts. Try
>
> exec "mozilla", "-remote", "openURL($URL, new-tab)";
>
> or
>
> exec "mozilla -remote \"openURL($URL, new-tab)\"";
>
> In the latter case, the shell will split up the arguments for you.
Actually, the shell will only be invoked, if there are shell
metacharacters in the string. If not, perl will split the string into
words before calling execvp(3). See perldoc -f exec.
--
Garry Williams
------------------------------
Date: Mon, 21 Oct 2002 15:19:43 -0400
From: "Christian Caron" <nospam@nospam.org>
Subject: format to output
Message-Id: <ap1k0f$3g85@nrn2.NRCan.gc.ca>
Hi everyone,
If I execute that:
#############
#!/usr/bin/perl -w
use strict;
my $variable1 = "scalar_one";
my @array1 = ("array1_one","array1_two","array1_three");
my @array2 = ("array2_one","array2_two");
format STDOUT =
@<<<<<<<<<<<<<<<
$variable1,
@*
@array1,
@*
@array2
.
write;
#############
I get:
colargol# ./test.pl
scalar_one
array1_one
array2_one
I would like to get:
scalar_one array1_one array2_one
array1_two array2_two
array1_three
Is this possible? I tried all combination (multiline ~~ ^<<<<<<, etc.) but I
can't figure out a way to do that...
Thanks!
------------------------------
Date: 21 Oct 2002 12:21:14 -0700
From: yw149@yahoo.com (miao mao)
Subject: how to igore the comments line in files?
Message-Id: <990eef2b.0210211121.4b251dc6@posting.google.com>
I need to generate a diff report between two versions of a file.
but I have to ignore the comments/header info.
Do you know how should I do that? Is there a script already written
for handling that?
thanks.
------------------------------
Date: 21 Oct 2002 14:20:49 -0700
From: laredotornado@zipmail.com (D. Alvarado)
Subject: How to use flock properly?
Message-Id: <9fe1f2ad.0210211320.35816215@posting.google.com>
Hi, I'm running on Solaris 5.8 and I was having a problem getting
flock to work the way I wanted. I have a single script, which looks
like this:
# Acquire the lock, or wait to acquire if another process holds it.
open LOCK_FILE, "$LOCK_FILE";
flock(LOCK_FILE, LOCK_EX);
... run program ...
# Release the lock, let other scripts continue.
flock(LOCK_FILE, LOCK_UN);
The "run program" part takes about 20 seconds to run and I log the
beginning and end times of the program execution. However, if I run 3
separate instances of this script, they all start about 1 or 2 seconds
after the other. I thought once one instance acquired the lock
through flock, the other instances were forced to wait when they tried
to acquire the lock through flock, but apparently I'm wrong.
What should I do to get the desired behavior?
Thanks, Dave
------------------------------
Date: Mon, 21 Oct 2002 21:24:14 GMT
From: shu wang <shu.wang2@verizon.net>
Subject: How to use script get login page?
Message-Id: <pan.2002.10.21.17.23.36.857211.1691@verizon.net>
Hi,
I have a script want to get a page, first get the login page, then fill
the from and send back, but what I got is the same login page. I don't
know what's wrong. Thanks for any help in advance!
my script is:
#!/usr/bin/perl
use LWP::UserAgent;
require LWP::UserAgent;
use HTML::Form;
my $ua = LWP::UserAgent->new(env_proxy => 1,
keep_alive => 1,
timeout => 30,
requests_redirectable=>['GET','POST','HEAD']
);
$ua->cookie_jar({ file => "$ENV{HOME}/.cookies.txt" });
$response = $ua->get('http://my.somesite.com/login.asp');
$form = HTML::Form->parse($response->content,$response->base());
$form->value(User => "user", Password =>"mypassword");
$response = $ua->request($form->click("submit"));
print $response->content;
------------------------------
Date: Mon, 21 Oct 2002 16:20:57 -0500
From: "Jerry Preston" <g-preston1@ti.com>
Subject: lost - map { "$_:\t$h->{$_}[0]\n"} keys %$h
Message-Id: <ap1r3l$e93$1@tilde.itg.ti.com>
Hi!
Can anyone explain to me how map works in this code?
for my $h (
# grab the Subject and Date from every message in my (fictional!) smut
folder;
# the first argument is a reference to an array listing all messages in
the folder
# (which is what gets returned by the $imap->search("ALL") method when
called in
# scalar context) and the remaining arguments are the fields to parse out
# The key is the message number, which in this case we don't care about:
values %{$imap->parse_headers( scalar($imap->search("ALL")) , "Subject",
"Date")}
) {
# $h is the value of each element in the hash ref returned from
parse_headers,
# and $h is also a reference to a hash.
# We'll only print the first occurance of each field because we don't
expect more
# than one Date: or Subject: line per message.
print map { "$_:\t$h->{$_}[0]\n"} keys %$h ;
}
How can I access this and break it done to look at each line?
Thanks,
Jerry
------------------------------
Date: Mon, 21 Oct 2002 13:29:25 -0500
From: "Jerry Preston" <g-preston1@ti.com>
Subject: new error
Message-Id: <ap1h21$9il$1@tilde.itg.ti.com>
Hi!
I get the following error:
Can't locate object method "new" via package
"Mail::IMAPClient::BodyStructure::Parse" at Mail/Client/BodyStructure.pm
line 15
What is wrong?
Thanks,
Jerry
------------------------------
Date: 21 Oct 2002 11:08:30 -0700
From: jeannot@gmavt.net (Jean Gagnon)
Subject: opendir/readdir can't handle french characters: What am I missing?
Message-Id: <981d6b93.0210211008.5ce876a2@posting.google.com>
Please forgive me if that's an obvious one, but as the title says, if
I do an opendir and then a readdir, a directory named "déménagement"
will show as "d8m8nagement". Can Perl handle these, am I missing a use
statement, or a runtime switch?
I am using Perl "v5.6.1 built for MSWin32-x86-multi-thread", running
on Windows 2000 and an NTFS file system.
Thanks guys.
------------------------------
Date: Mon, 21 Oct 2002 18:24:42 GMT
From: "John W. Krahn" <krahnj@acm.org>
Subject: Re: opendir/readdir can't handle french characters: What am I missing?
Message-Id: <3DB4467F.B3663DB9@acm.org>
Jean Gagnon wrote:
>
> Please forgive me if that's an obvious one, but as the title says, if
> I do an opendir and then a readdir, a directory named "déménagement"
> will show as "d8m8nagement". Can Perl handle these, am I missing a use
> statement, or a runtime switch?
Yes, perl can handle these. Did you get an error message when you tried
it?
John
--
use Perl;
program
fulfillment
------------------------------
Date: 21 Oct 2002 11:26:59 -0700
From: ben.rogers@escalate.com (benrog)
Subject: parsing XML to FrameMaker: newline troubles in regex
Message-Id: <1da5d446.0210211026.52e23c02@posting.google.com>
After reading one camel, a llama, this newsgroup, surfing the
internet, and generally frustrating myself for hours and hours, I have
to ask:
I've written a program that reads an XML file, prints some of it's
contents into a fake Java file, and then invokes Sun's MIFDoclet to
parse the .java file in to FrameMaker and PDF docs. Peachy. What's
bothering me is that I can't get my regex to match across newlines.
What's worse is that what I read seems clear enough but I can't get it
to work. I am thinking that it must be my implementation of the regex
rather than the regex itself. In any case, I'm reduced to trying
random things and am soon to go postal.
What I want is to match everything from the beginning of an element to
the end. Thus, I want everything starting with <element and ending
with the first >.
<element name="merchantSkuRefNumber"
forfutureuse="" formatsize="AN100"
loadtable="tn_load_sku (LDSKU)"
prefixtable="tn_load_general_prefix (LPGEN)"
tablecolumn="tn_merchant_sku.ms_vendor_specific_id"
description="merchant sku vendor specific id, uniquely identifies
merchant sku"
edivalues=""
escalatevalues=""
edispec="VICS 850"
edilevel="PO Detail or PO Summary"
edisegment="PO107"
edipositionnumber="010"
edidataelement="234"
shipping=""
errorcode=""
getmethod=""
notes=""
seealso=""
/>
Here are my tries. I've actually tried far more than this, but I just
don't understand why /^<whateveriputinhere>$/s doesn't give me what I
want.
if (/(^<element.*>)$/si)
if (/(^<element.*)>$/si)
if (/^<element(.*)>$/si)
if (/^<element.*/si)
if (/(^<element.*>)$/sim)
if (/(^<element.*)>$/sim)
if (/^<element(.*)>$/sim)
if (/^<element.*/sim)
if (/(^<element.*>)$/im)
if (/(^<element.*)>$/im)
if (/^<element(.*)>$/im)
if (/^<element.*/im)
if (/(^<element.*>)$/sim)
if (/(^<element.*)>$/sim)
if (/^<element(.*)+>$/sim)
if (/^<element.*\s.*/sim)
/^<element.*\s.*/s
if (/^<element.*/s)
if (/^<ele(.*)+/s)
Thanks in advance for any help.
ben
------------------------------
Date: Mon, 21 Oct 2002 14:22:32 -0500
From: cp <cpryce@pryce.net>
Subject: Re: parsing XML to FrameMaker: newline troubles in regex
Message-Id: <B9D9BE28.10746%cpryce@pryce.net>
in article 1da5d446.0210211026.52e23c02@posting.google.com, benrog at
ben.rogers@escalate.com wrote on 10/21/02 1:26 PM:
> After reading one camel, a llama, this newsgroup, surfing the
> internet, and generally frustrating myself for hours and hours, I have
> to ask:
>
> I've written a program that reads an XML file, prints some of it's
> contents into a fake Java file, and then invokes Sun's MIFDoclet to
> parse the .java file in to FrameMaker and PDF docs. Peachy. What's
> bothering me is that I can't get my regex to match across newlines.
> What's worse is that what I read seems clear enough but I can't get it
> to work. I am thinking that it must be my implementation of the regex
> rather than the regex itself. In any case, I'm reduced to trying
> random things and am soon to go postal.
>
> What I want is to match everything from the beginning of an element to
> the end. Thus, I want everything starting with <element and ending
> with the first >.
[ snip example]
>
> Here are my tries. I've actually tried far more than this, but I just
> don't understand why /^<whateveriputinhere>$/s doesn't give me what I
> want.
[ snip regex examples ]
What you are finding is the XML, like HTML is hard to parse with a simple
regex. Parsing XML is best left to - at the risk of sounding like a
smart-alec - an XML parser. The expression most often invoked here is, why
re-invent the wheel?
A partial list of Perl solutions is compiled here:
http://perl-xml.sourceforge.net/faq/. All of the modules listed in this
document are available on the CPAN.
Other solutions might present themselves at: http://xml.apache.org/.
cp
------------------------------
Date: Mon, 21 Oct 2002 15:14:12 -0500
From: tadmc@augustmail.com (Tad McClellan)
Subject: Re: parsing XML to FrameMaker: newline troubles in regex
Message-Id: <slrnar8o0k.26k.tadmc@magna.augustmail.com>
benrog <ben.rogers@escalate.com> wrote:
> After reading one camel, a llama, this newsgroup, surfing the
> internet, and generally frustrating myself for hours and hours, I have
> to ask:
> Peachy. What's
> bothering me is that I can't get my regex to match across newlines.
There are *two* things to consider when a pattern match isn't
working as you expect it too: the pattern, and the string that
the pattern is to be matched against.
You make no mention of the second one.
Do you _have_ a multiline string to match against?
But that shouldn't matter much, as you should not even _want_
a regex for processing XML.
You should use a module that understands XML for processing
XML data.
A regex "solution" is likely to do The Wrong Thing with
this, for example:
<!--
<element name="merchantSkuRefNumber" />
-->
> What I want is to match everything from the beginning of an element to
> the end. Thus, I want everything starting with <element and ending
> with the first >.
> Here are my tries. I've actually tried far more than this, but I just
> don't understand why /^<whateveriputinhere>$/s doesn't give me what I
> want.
We only have half of what we need to evaluate what is going on,
so we don't understand either. :-)
This "works" (matches) for me:
-----------------------------------
#!/usr/bin/perl
use warnings;
use strict;
$_ = '<element name="merchantSkuRefNumber"
forfutureuse="" formatsize="AN100"
loadtable="tn_load_sku (LDSKU)"
prefixtable="tn_load_general_prefix (LPGEN)"
tablecolumn="tn_merchant_sku.ms_vendor_specific_id"
description="merchant sku vendor specific id, uniquely identifies merchant sku"
edivalues=""
escalatevalues=""
edispec="VICS 850"
edilevel="PO Detail or PO Summary"
edisegment="PO107"
edipositionnumber="010"
edidataelement="234"
shipping=""
errorcode=""
getmethod=""
notes=""
seealso=""
/>';
print "matched\n" if /<element[^>]*>/;
-----------------------------------
> Thanks in advance for any help.
My guess is that your Question is Asked Frequently, you
must have missed it:
perldoc -q match
"I'm having trouble matching over more than one line. What's wrong?"
--
Tad McClellan SGML consulting
tadmc@augustmail.com Perl programming
Fort Worth, Texas
------------------------------
Date: 21 Oct 2002 14:26:06 -0700
From: jl_post@hotmail.com (J. Romano)
Subject: Question about hash entries with two keys
Message-Id: <b893f5d4.0210211326.73f925e9@posting.google.com>
Dear Perl community,
This post concerns hashes that use two keys for each entry.
A lot of people don't know this, but a hash entry in Perl can take
two keys and one value (instead of the more traditional one key and
one value). This is useful in case I want to emulate a database table
that uses two fields (or columns) as the primary key. Let me give an
example:
Say I'm a teacher at a school, and not only do I teach dozens of
students, I also teach several classes (like Math, Language Arts,
Social Studies, etc.). I want to record my students' grades in a
hash, but I don't want to have one hash for each class -- that is, I
want to have one hash that includes all my classes and all my
students.
Fortunately, Perl can handle this. If I want to give my student
Bob a 95% in Math class and a 90% in Social Studies, I can write:
$grades{"bob","math"} = 95;
$grades{"bob","social studies"} = 90;
If I wish to extract and view an entry from the %grades hash table,
I can type:
($key,$value) = each(%grades);
print "\$key = $key \$value = $value\n";
which gives output like the following:
$key = bobmath $value = 95
$firstKey = bob $secondKey = math
I remember reading in a Perl book that Perl manages two-key hash
entries by concatenating the keys together with a special character.
This is apparent in the above output, when we see that the key is set
to "bobmath".
My question is: how do I extract both keys from that entry, so
that I can have "bob" in one variable, and "math" in another? It's
not like I can split those values out very easily, because I don't
normally type the "" character. Even if I did, I couldn't be sure
that all versions of Perl use that character to concatenate the two
keys, so my program might not be portable.
Before I end this post, let me say that I did discover one way of
splitting out the keys by extracting out the "splitting character"
from a dummy hash that has a key of two null strings. Let me show the
code that does this:
# First, I create a dummy hash with one dummy entry:
$dummyHash{"",""} = undef;
# Then I extract the key and value:
($char,undef) = each(%dummyHash);
# The key (stored in $char) should now be just the "" character
# Now I can split both keys out:
($firstKey,$secondKey) = split($char,$key);
For those who want to see the code in a proper context, let me
include a short test program I wrote to demonstrate this:
#!/usr/bin/perl -w
$grades{"bob","math"} = 95;
($key,$value) = each(%grades);
print "\$key = $key \$value = $value\n";
$dummyHash{"",""} = undef;
($char,undef) = each(%dummyHash);
($firstKey,$secondKey) = split($char,$key);
print "\$firstKey = $firstKey \$secondKey = $secondKey\n";
# end of test script
Granted, the above method does exactly what I want it to, but I
have to create a dummy hash with a dummy entry just to extract the
character to use with the split function. Shouldn't there be an
easier way to do this? I would think that Perl already provides an
easier way to do this.
If anybody knows another way to do this, please let me know.
Thanks in advance,
Jean-Luc Romano
------------------------------
Date: Mon, 21 Oct 2002 21:42:03 GMT
From: tiltonj@erols.com (Jay Tilton)
Subject: Re: Question about hash entries with two keys
Message-Id: <3db473f2.278908585@news.erols.com>
jl_post@hotmail.com (J. Romano) wrote:
: My question is: how do I extract both keys from that entry, so
: that I can have "bob" in one variable, and "math" in another? It's
: not like I can split those values out very easily, because I don't
: normally type the "" character. Even if I did, I couldn't be sure
: that all versions of Perl use that character to concatenate the two
: keys, so my program might not be portable.
Perldoc perlvar
Look for $;
------------------------------
Date: 21 Oct 2002 21:48:49 GMT
From: "Tassilo v. Parseval" <tassilo.parseval@post.rwth-aachen.de>
Subject: Re: Question about hash entries with two keys
Message-Id: <ap1so1$49u$1@nets3.rz.RWTH-Aachen.DE>
Also sprach J. Romano:
> This post concerns hashes that use two keys for each entry.
>
> A lot of people don't know this, but a hash entry in Perl can take
> two keys and one value (instead of the more traditional one key and
> one value). This is useful in case I want to emulate a database table
> that uses two fields (or columns) as the primary key. Let me give an
> example:
Indeed, a lot of people forgot about that. :-) It is now obsolete since
you can store references to other complex data structures in your hash.
Be aware though, that you do not really have two keys both associated
with one value. Internally, this is still one key. You mentioned that
yourself further down.
> Say I'm a teacher at a school, and not only do I teach dozens of
> students, I also teach several classes (like Math, Language Arts,
> Social Studies, etc.). I want to record my students' grades in a
> hash, but I don't want to have one hash for each class -- that is, I
> want to have one hash that includes all my classes and all my
> students.
>
> Fortunately, Perl can handle this. If I want to give my student
> Bob a 95% in Math class and a 90% in Social Studies, I can write:
>
> $grades{"bob","math"} = 95;
> $grades{"bob","social studies"} = 90;
>
> If I wish to extract and view an entry from the %grades hash table,
> I can type:
>
> ($key,$value) = each(%grades);
> print "\$key = $key \$value = $value\n";
>
> which gives output like the following:
>
> $key = bobmath $value = 95
> $firstKey = bob $secondKey = math
>
> I remember reading in a Perl book that Perl manages two-key hash
> entries by concatenating the keys together with a special character.
Yes, true. I heard that \0 is used for that.
> This is apparent in the above output, when we see that the key is set
> to "bobmath".
>
> My question is: how do I extract both keys from that entry, so
> that I can have "bob" in one variable, and "math" in another? It's
> not like I can split those values out very easily, because I don't
> normally type the "" character. Even if I did, I couldn't be sure
> that all versions of Perl use that character to concatenate the two
> keys, so my program might not be portable.
You start differently so that this problem does not exist. This:
$grades{"bob","math"} = 95;
$grades{"bob","social studies"} = 90;
will become:
$grades{bob} = {
'math' => 95,
'social studies' => 90,
};
# or more ressembling your notion
$grades{bob}->{math} = 95;
$grades{bob}->'social studies'} = 90;
{ LIST } creates a reference to an anonymous (that is, no name
associated with it) hash.
Accessing your data no longer requires a split now:
while (my ($key, $value) = each %grades) {
# remember that $value is a reference to a hash
print "$key's grades:\n";
while (my ($sbj, $grd) = each %$value) {
print "$sbj: $grd\n";
}
}
Also see 'perldoc perlref|perlreftut|perldsc'. You need to be acquainted
with references to use multidimensional hashes and arrays in Perl.
Tassilo
--
$_=q!",}])(tsuJ[{@"tnirp}3..0}_$;//::niam/s~=)]3[))_$-3(rellac(=_$({
pam{rekcahbus;})(rekcah{lrePbus;})(lreP{rehtonabus;})(rehtona{tsuJbus!;
$_=reverse;s/sub/(reverse"bus").chr(32)/xge;tr~\n~~d;eval;
------------------------------
Date: Mon, 21 Oct 2002 21:48:54 GMT
From: Uri Guttman <uri@stemsystems.com>
Subject: Re: Question about hash entries with two keys
Message-Id: <x7elajjwe2.fsf@mail.sysarch.com>
>>>>> "JR" == J Romano <jl_post@hotmail.com> writes:
JR> Dear Perl community,
JR> This post concerns hashes that use two keys for each entry.
JR> A lot of people don't know this, but a hash entry in Perl can take
JR> two keys and one value (instead of the more traditional one key and
JR> one value). This is useful in case I want to emulate a database table
JR> that uses two fields (or columns) as the primary key. Let me give an
JR> example:
that is called fake multidimensional arrays and dates from the perl4
days. it is not recommended for use in perl5. real perl data structures
are better in many ways.
and i wouldn't call that two keys and one value. more below.
JR> Fortunately, Perl can handle this. If I want to give my student
JR> Bob a 95% in Math class and a 90% in Social Studies, I can write:
JR> $grades{"bob","math"} = 95;
JR> $grades{"bob","social studies"} = 90;
this is the way to do that:
$grades{"bob"}{"math"} = 95;
$grades{"bob"}{"social studies"} = 90;
JR> which gives output like the following:
JR> $key = bobmath $value = 95
JR> $firstKey = bob $secondKey = math
JR> I remember reading in a Perl book that Perl manages two-key hash
JR> entries by concatenating the keys together with a special character.
JR> This is apparent in the above output, when we see that the key is set
JR> to "bobmath".
JR> My question is: how do I extract both keys from that entry, so
JR> that I can have "bob" in one variable, and "math" in another? It's
JR> not like I can split those values out very easily, because I don't
JR> normally type the "" character. Even if I did, I couldn't be sure
JR> that all versions of Perl use that character to concatenate the two
JR> keys, so my program might not be portable.
read perlvar and look for $;
JR> Before I end this post, let me say that I did discover one way of
JR> splitting out the keys by extracting out the "splitting character"
JR> from a dummy hash that has a key of two null strings. Let me show the
JR> code that does this:
JR> Granted, the above method does exactly what I want it to, but I
JR> have to create a dummy hash with a dummy entry just to extract the
JR> character to use with the split function. Shouldn't there be an
JR> easier way to do this? I would think that Perl already provides an
JR> easier way to do this.
please use real perl data structures. i doubt anyone will actually help
you with your perceived goals as they are very misguided. the fake
multi-dim array stuff is not useful at all.
for more on perl structures read perllol and perldsc. also the perl
cookbook has some good stuff on it.
whatever book you have that promotes fake multi-dim arrays should be
burned. which one is it anyhow? i want to downrate it.
uri
--
Uri Guttman ------ uri@stemsystems.com -------- http://www.stemsystems.com
----- Stem and Perl Development, Systems Architecture, Design and Coding ----
Search or Offer Perl Jobs ---------------------------- http://jobs.perl.org
------------------------------
Date: Mon, 21 Oct 2002 16:35:42 -0400
From: "Neil MacMurchy" <neilmcse@hotmail.com>
Subject: Re: Stopping IIS website
Message-Id: <uulcn$TeCHA.1796@tkmsftngp12>
typing net services and hitting enter at a command prompt will show a list
of services available to stop or start. After that typing in Net Start
NameofService or Net Stop NameofService will do the job.
for individual sites there are the startweb and stopweb (and also Startftp
and stopftp) scripts.
Neil MacMurchy
"William Hymen" <t18_pilot@hotmail.spam.com> wrote in message
news:3NRs9.6878$U97.630709@newsread2.prod.itd.earthlink.net...
> I can stop my web server with
> Net Stop "World Wide Web Publishing Service"
>
> How do I stop an individual site from command line?
> Maybe VB or Perl?
>
> Any examples would be great.
>
> Thanks.
>
> Bill
>
>
------------------------------
Date: 6 Apr 2001 21:33:47 GMT (Last modified)
From: Perl-Users-Request@ruby.oce.orst.edu (Perl-Users-Digest Admin)
Subject: Digest Administrivia (Last modified: 6 Apr 01)
Message-Id: <null>
Administrivia:
The Perl-Users Digest is a retransmission of the USENET newsgroup
comp.lang.perl.misc. For subscription or unsubscription requests, send
the single line:
subscribe perl-users
or:
unsubscribe perl-users
to almanac@ruby.oce.orst.edu.
To submit articles to comp.lang.perl.announce, send your article to
clpa@perl.com.
To request back copies (available for a week or so), send your request
to almanac@ruby.oce.orst.edu with the command "send perl-users x.y",
where x is the volume number and y is the issue number.
For other requests pertaining to the digest, send mail to
perl-users-request@ruby.oce.orst.edu. Do not waste your time or mine
sending perl questions to the -request address, I don't have time to
answer them even if I did know the answer.
------------------------------
End of Perl-Users Digest V10 Issue 4007
***************************************