[16655] in Perl-Users-Digest

home help back first fref pref prev next nref lref last post

Perl-Users Digest, Issue: 4067 Volume: 9

daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Sat Aug 19 14:10:52 2000

Date: Sat, 19 Aug 2000 11:10:17 -0700 (PDT)
From: Perl-Users Digest <Perl-Users-Request@ruby.OCE.ORST.EDU>
To: Perl-Users@ruby.OCE.ORST.EDU (Perl-Users Digest)
Message-Id: <966708617-v9-i4067@ruby.oce.orst.edu>
Content-Type: text

Perl-Users Digest           Sat, 19 Aug 2000     Volume: 9 Number: 4067

Today's topics:
    Re: help with RegExp (Keith Calvert Ivey)
    Re: HELP: interpolation of patterns and the pos command (Marcel Grunauer)
    Re: HTML::Parser (Kevin Reid)
    Re: Newbie - print here problem (Marcel Grunauer)
    Re: obfusicate routine to count max string len in hash (Logan Shaw)
    Re: obfusicate routine to count max string len in hash (Abigail)
    Re: obfusicate routine to count max string len in hash (Keith Calvert Ivey)
    Re: Passing argument to Perl script <lary@bigfoot.com>
    Re: Perl and visual Basic (Marcel Grunauer)
    Re: Problem with hash initialization using list (Abigail)
    Re: Problem with hash initialization using list (Keith Calvert Ivey)
    Re: Problem with hash initialization using list <rick.delaney@home.com>
    Re: Simple regex problem (Keith Calvert Ivey)
        subject with smtp.pm <danielxx@bart.nl>
        using perl to interact with a telnet session (Shao Zhang)
    Re: using perl to interact with a telnet session (Marcel Grunauer)
    Re: using perl to interact with a telnet session (NP)
        Digest Administrivia (Last modified: 16 Sep 99) (Perl-Users-Digest Admin)

----------------------------------------------------------------------

Date: Sat, 19 Aug 2000 15:24:03 GMT
From: kcivey@cpcug.org (Keith Calvert Ivey)
Subject: Re: help with RegExp
Message-Id: <39a1a546.6860762@news.newsguy.com>

"Alex T." <samara_biz@hotmail.com> wrote:

>WHITE<any number of blanks>JR
>should become WHITE
>
>ST<any number of blanks>LOUIS<any number of blanks>III
>should become ST LOUIS
>
>I tried this:
>
>$lastname =~ s/([\w|\s]+?)\s+?(\w+?)$/$1/i;
>
>and a few other ways, but I couldn't get it to work. How can I do it?

Your regex works for me.  There must be something wrong with the
way you're using it.

Of course, your regex is rather strange.  For example, in
includes | in the character class, which will be interpreted as
a literal pipe character, and the question marks are
unnecessary, and there's no point in having \s in the character
class.  Anyway, how are you going to avoid deleting the "LOUIS"
in "ST LOUIS" if there's no "III"?  You might want to use
something like this:

    $lastname =~ s/,?\s+(?:[js]r\.?|v?i{1,3}|i?v)$//i;

-- 
Keith C. Ivey <kcivey@cpcug.org>
Washington, DC


------------------------------

Date: Sat, 19 Aug 2000 13:40:02 GMT
From: marcel@codewerk.com (Marcel Grunauer)
Subject: Re: HELP: interpolation of patterns and the pos command
Message-Id: <slrn8pt3gs.48d.marcel@gandalf.local>

On 18 Aug 2000 20:02:43 -0400, Dragomir R. Radev
<radev@quip.eecs.umich.edu> wrote:

>I am trying to see where in $long does a substring $short appear.

If you are only trying to find a fixed substring, use index().

perldoc -f index

>The code above works fine except in the cases where $short and $long
>contain special symbols.

If you need to use a regex and you have special characters that need to
be escaped, use quotemeta() or the '\Q' escape in double-quoted strings.

perldoc -f quotemeta

-- 
Marcel Gr\"unauer - Codewerk plc . . . . . . . . . . . <http://www.codewerk.com>
Perl Consulting, Programming, Training, Code review . . .  <marcel@codewerk.com>
mod_perl, XML solutions - email for consultancy availability
sub AUTOLOAD{($_=$AUTOLOAD)=~s;^.*::;;;y;_; ;;print} Just_Another_Perl_Hacker();


------------------------------

Date: Sat, 19 Aug 2000 09:05:23 -0400
From: kpreid@attglobal.net (Kevin Reid)
Subject: Re: HTML::Parser
Message-Id: <1efkbik.67pe2mo0qn20N%kpreid@attglobal.net>

Gabe <grichard@uci.edu> wrote:

> The docs say $p->parse_file($file) returns a reference to the parser
> object. What does this mean? I know what a reference is, but what's th
> parser object? Isn't that $p?

Exactly. That feature is so you can do something like:

HTML::Parser->new()->parse_file($somefile)->some_other_method();

for one-liners and such.

> I want to print the content of the HTML page in question, I'm using the
> right module right? How do I print what HTML::Parser finds?

HTML::Parser does nothing except parse. To do anything useful with it,
you have to subclass it - see HTML::LinkExtor for an example.

-- 
 Kevin Reid: |    Macintosh:      
  "I'm me."  | Think different.


------------------------------

Date: Sat, 19 Aug 2000 13:49:59 GMT
From: marcel@codewerk.com (Marcel Grunauer)
Subject: Re: Newbie - print here problem
Message-Id: <slrn8pt42o.4cm.marcel@gandalf.local>

On Thu, 17 Aug 2000 08:44:45 GMT, scottfreez@my-deja.com
<scottfreez@my-deja.com> wrote:

>print<<FINISH;
>Content-type: text/html
>
>hey there
>FINISH
>
>Can't find string terminator "FINISH" anywhere before EOF at
>C:\Inetpub\wwwroot\perl\flockansi.pl line 1.


Is the terminator, "FINISH", on a line by itself and starting right at
the first column, without any white space before it?


-- 
Marcel Gr\"unauer - Codewerk plc . . . . . . . . . . . <http://www.codewerk.com>
Perl Consulting, Programming, Training, Code review . . .  <marcel@codewerk.com>
mod_perl, XML solutions - email for consultancy availability
sub AUTOLOAD{($_=$AUTOLOAD)=~s;^.*::;;;y;_; ;;print} Just_Another_Perl_Hacker();


------------------------------

Date: 19 Aug 2000 08:41:10 -0500
From: logan@cs.utexas.edu (Logan Shaw)
Subject: Re: obfusicate routine to count max string len in hash
Message-Id: <8nm2pm$llj$1@provolone.cs.utexas.edu>

In article <MPG.1407c18ee18ed9f398ac9f@nntp.hpl.hp.com>,
Larry Rosler  <lr@hpl.hp.com> wrote:
>In article <8nl4e7$kmg$1@provolone.cs.utexas.edu>, logan@cs.utexas.edu 
>says...
>+ In article <slrn8ps2cu.tj3.abigail@alexandra.foad.org>,
>+ Abigail <abigail@foad.org> wrote:
>+ >One stroke less:
>+ >
>+ >         $x=(sort{$b<=>$a}map y===c,keys%hash)[0];
>+ 
>+ O.K., combining that with the idea of looking at the last element of
>+ the list, we get this:
>+ 
>+ 	$x=(sort map(y===c,keys%hash)[-1];
>+ 
>+ Which I believe is the shortest yet.
>
>But even if the syntax error is fixed, it is quite wrong, as it sorts on 
>the lexicographic values of the lengths, not on their numerical values 
>(i.e., 1, 10, 2, ...).  Don't you think that testing what you post is a 
>good idea?

Well, I did test it, but it turns out I didn't think to use any strings
long enough to make the lexicographic vs. numeric ordering make a
diference.  And then I somehow I lost a parenthesis in the process of
moving it from test script into the post.  Darn!

  - Logan


------------------------------

Date: 19 Aug 2000 13:50:39 GMT
From: abigail@foad.org (Abigail)
Subject: Re: obfusicate routine to count max string len in hash
Message-Id: <slrn8pt448.tj3.abigail@alexandra.foad.org>

Logan Shaw (logan@cs.utexas.edu) wrote on MMDXLV September MCMXCIII in
<URL:news:8nl4e7$kmg$1@provolone.cs.utexas.edu>:
-- In article <slrn8ps2cu.tj3.abigail@alexandra.foad.org>,
-- Abigail <abigail@foad.org> wrote:
-- >Larry Rosler (lr@hpl.hp.com) wrote on MMDXLIV September MCMXCIII in
-- ><URL:news:MPG.14075d9118a393ab98ac9b@nntp.hpl.hp.com>:
-- >)) 
-- >)) The correct answer (as observed later):
-- >)) 
-- >))       $x=(sort{$b<=>$a}map length,keys%hash)[0];
-- >
-- >One stroke less:
-- >
-- >         $x=(sort{$b<=>$a}map y===c,keys%hash)[0];
--
-- O.K., combining that with the idea of looking at the last element of
-- the list, we get this:
--
-- 	$x=(sort map(y===c,keys%hash)[-1];
                    ^ that needs to be a space or a +


However:

    #!/opt/perl/bin/perl -w

    use strict;

    my %hash = (foobarbaz  =>  9,
                foobarbaz1 => 10);
    my $x;

    $x=(sort map y===c,keys%hash)[-1];

    print $x, "\n";
    __END__
    9

And that's because C<< 10 lt 9 >>, but C<< 10 > 9 >>.


Abigail
-- 
srand 123456;$-=rand$_--=>@[[$-,$_]=@[[$_,$-]for(reverse+1..(@[=split
//=>"IGrACVGQ\x02GJCWVhP\x02PL\x02jNMP"));print+(map{$_^q^"^}@[),"\n"


------------------------------

Date: Sat, 19 Aug 2000 15:42:16 GMT
From: kcivey@cpcug.org (Keith Calvert Ivey)
Subject: Re: obfusicate routine to count max string len in hash
Message-Id: <39a2aa70.8183019@news.newsguy.com>

Larry Rosler <lr@hpl.hp.com> wrote:
>Jim Mauldin <mauldin@netstorm.net> says...
>> Larry Rosler wrote:

>> >   print length +(sort keys %hash)[-1];
>> 
>> Very nice as usual, Larry, but help me out here.
>
>But wrong; see below.
>
>>                                                   I believed the
>> +(whatever) construct to be essentially a precedence manager.
>
>In this case, it disambiguates the left paren from being the beginning 
>of a parenthesized arg list for print().

You meant length(), not print(), of course.

-- 
Keith C. Ivey <kcivey@cpcug.org>
Washington, DC


------------------------------

Date: Sat, 19 Aug 2000 16:16:19 +0200
From: "Lary" <lary@bigfoot.com>
Subject: Re: Passing argument to Perl script
Message-Id: <399e88ed@news.barak.net.il>

user the -s command line option (or on unix invoke perl with the -s option:
#!/usr/local/perl -s  ).
If you write on the command line:

perl -s myprogram.pl -a=5 -b=6 -c=7

you will get in the program the variables $a $b $c with the values from the
command line

/L\
lary@bigfoot.com

"Jonathan Stowe" <gellyfish@gellyfish.com> wrote in message
news:8nlmu2$f54$1@orpheus.gellyfish.com...
> On Sat, 19 Aug 2000 11:51:43 +1000 Minh Le wrote:
> > Hi,
> > I'm trying to pass 3 different arguments to my simple perl script
without
> > any success.  I did try GetOption ... but they are all failed.
> > What I need is during execute my script, I need to pass 3 different
> > arguments to the program and depend on which argument has been provided,
a
> > particular sub-routine or task will be called.
> > Example:  myperl -a x  -b x -c x
> > where x can be 0 or 1.  if there is no option or argument provided, it
will
> > print out a help message, say " Please run myperl -help"
> >
>
> You will probably want to use the module Getopt::Std to do this - in your
> case you will have something similar to :
>
>
> #!/usr/bin/perl -w
>
> use Getopt::Std;
> use strict;
>
> my %opts;
>
> getopts('a:b:c:',\%opts) || die "Invalid argument\n";
>
> unless(exists $opts{a} &&
>        exists $opts{b} &&
>        exists $opts{c} )
> {
>   die "You must supply all of the arguments\n";
> }
>
>
> /J\
> --
> yapc::Europe in assocation with the Institute Of Contemporary Arts
>    <http://www.yapc.org/Europe/>   <http://www.ica.org.uk>




------------------------------

Date: Sat, 19 Aug 2000 13:53:59 GMT
From: marcel@codewerk.com (Marcel Grunauer)
Subject: Re: Perl and visual Basic
Message-Id: <slrn8pt4av.4cm.marcel@gandalf.local>

On Fri, 18 Aug 2000 21:29:36 GMT, marc.pauwels@skynet.be
<marc.pauwels@skynet.be> wrote:

>I have some troubles to return a string from a visual basic program, which 
>is called from a PERL script into a perl variable. 
>ex. 
>
>     $perlvar = my_vb_program("var1,var2.....") ;
>
>How can I get the returned string into my $perlvar and syntax of my the 
>visual basic code ?  


Use backticks. See "perldoc perlop", search for 'qx/STRING/'.

Also read the FAQ: "perldoc -q backticks" ("How can I call backticks
without shell processing?").

-- 
Marcel Gr\"unauer - Codewerk plc . . . . . . . . . . . <http://www.codewerk.com>
Perl Consulting, Programming, Training, Code review . . .  <marcel@codewerk.com>
mod_perl, XML solutions - email for consultancy availability
sub AUTOLOAD{($_=$AUTOLOAD)=~s;^.*::;;;y;_; ;;print} Just_Another_Perl_Hacker();


------------------------------

Date: 19 Aug 2000 14:03:11 GMT
From: abigail@foad.org (Abigail)
Subject: Re: Problem with hash initialization using list
Message-Id: <slrn8pt4ro.tj3.abigail@alexandra.foad.org>

Anno Siegel (anno4000@lublin.zrz.tu-berlin.de) wrote on MMDXLIV September
MCMXCIII in <URL:news:8nj8q0$o5h$1@lublin.zrz.tu-berlin.de>:
{} Priit Randla <priitr.randla@eyp.ee> wrote in comp.lang.perl.misc:
{} >	Hello
{} >
{} >   I have a configuration file whose lines look like key=value.
{} > I'd like to initialize a hash using something like this:
{} > ($key,$info{$key}) = split /=/ while <> ;
{} > Obviously this does not work and i do understand why($key not evaluated yet
{} > when evaluating $info{$key}).
{} > Is there some way to initialize hash _elements_ using lists as 
{} > %hash = ($key1, $val1, $key2, $val2 ) is doing for _entire_ hash?
{} > I'm simply trying to avoid unneccessary temporary variables.
{} 
{} This does what I think you want to do:
{} 
{}    %info = map split( /=/), <>;
{} 
{} but unlike your lie-wise approach it reads the whole file into memory.

Yeah, but since you're keeping everything of the file in the hash anyway,
this should not to much of a problem. At most doubling of your memory,
unless you have many duplicates.

{} Another problem (that it shares with your approach) is that it neglects
{} to chomp() the input lines, so all the values in %info are going to
{} have a trailing newline.
{} 
{}    map chomp, values %info
{} 
{} can correct that, but that's map in void context, anathema to some.
{} 
{} Blindly accepting everything on each side of a "=" may turn out
{} to be a problem too if the configuration file isn't very carefully
{} maintained.  It's probably best in a case like this to put up with
{} a temporary variable or two (lexicals, of course), and do some
{} cleanup and checking at leisure.

Or use the 3 argument form of split.

    %info = map {chomp; split /=/ => $_, 2} <>;

Or:

    %info = map {/^([^=]*)=(.*)/} <>;


Abigail
-- 
 :;$:=~s:
-:;another Perl Hacker
 :;chop
$:;$:=~y
 :;::d;print+Just.
$:;


------------------------------

Date: Sat, 19 Aug 2000 15:03:15 GMT
From: kcivey@cpcug.org (Keith Calvert Ivey)
Subject: Re: Problem with hash initialization using list
Message-Id: <39a0a114.5786740@news.newsguy.com>

Larry Rosler <lr@hpl.hp.com> wrote:

>So why not write it as
>
>     chomp for values %info;
>
>One token fewer, at that!
>
>Note to the unwary:  The values() function wasn't lvaluable until 5.6.0.  

If it's really lvaluable, shouldn't you be able to do

    chomp values %info

to save another token?

-- 
Keith C. Ivey <kcivey@cpcug.org>
Washington, DC


------------------------------

Date: Sat, 19 Aug 2000 16:39:08 GMT
From: Rick Delaney <rick.delaney@home.com>
Subject: Re: Problem with hash initialization using list
Message-Id: <399EBA72.D8FE82FC@home.com>


Keith Calvert Ivey wrote:
> 
> Larry Rosler <lr@hpl.hp.com> wrote:
> 
> >So why not write it as
> >
> >     chomp for values %info;
> >
> >One token fewer, at that!
> >
> >Note to the unwary:  The values() function wasn't lvaluable until 5.6.0.
> 
> If it's really lvaluable, shouldn't you be able to do
> 
>     chomp values %info
> 
> to save another token?

I'd think so.  But if you just want to save tokens you can do

    chomp %info;

in 5.6 or 5.5.3.  I'm not sure how far back this works.  It isn't
documented very well.  Up until today I didn't know you could do this
and I only found out by poking through the source for the cause of the
bug you mentioned.

-- 
Rick Delaney
rick.delaney@home.com


------------------------------

Date: Sat, 19 Aug 2000 15:59:43 GMT
From: kcivey@cpcug.org (Keith Calvert Ivey)
Subject: Re: Simple regex problem
Message-Id: <39a3ae09.9104453@news.newsguy.com>

Drew Simonis <care227@attglobal.net> wrote:

>why not just use split()?
>
>($header, $footer) = split /\n\n/, $variable;

It's not a footer, it's the body of an e-mail message, and it's
likely to contain multiple paragraphs, which your solution will
discard.  Add a third argument to split():

    ($header, $body) = split /\n\n/, $variable, 2;

-- 
Keith C. Ivey <kcivey@cpcug.org>
Washington, DC


------------------------------

Date: Sat, 19 Aug 2000 16:27:06 GMT
From: "Daniel van den Oord" <danielxx@bart.nl>
Subject: subject with smtp.pm
Message-Id: <uzyn5.22974$Gd1.143506@Typhoon.bART.nl>

I'm using NT server and perl 5.6.
I have written a script sending an email using smtp.pm the script it self is
below
I'm wondering how to send an subject/header with it ?!? hope anybody can
help ?!?

  $smtp = Net::SMTP->new($mailhost,
                     Hello => $sending_host,
                     Debug => 0
                     );
  $smtp->mail($users_email);
  $smtp->to($mail);
  $smtp->data();
  $smtp->datasend(<<EOF_MAIL);
  Senders name    : $users_name
  Senders email   : $users_email
  Senders message : $message
EOF_MAIL
  $smtp->dataend();
  $smtp->quit;







------------------------------

Date: 20 Aug 2000 00:59:40 +1000
From: shao@cia.com.au (Shao Zhang)
Subject: using perl to interact with a telnet session
Message-Id: <399ea0dc@news>

Hi,
	I am trying to use perl to do the following equivalent. But my
	program does not work. Any one give me some hints??

In Shell,
	(sleep 3; echo $username; echo; sleep 2; echo $passwd;
	echo; sleep 2; echo $message; sleep 2; echo $quit; echo;) |
	telnet $server");

In perl,
	open(HANDLE, "|telnet $server");
	sleep 3; print HANDLE "$username\n";
	sleep 2; print HANDLE "$passwd\n";
	sleep 2; print HANDLE "$message\n";
	sleep 2; print HANDLE "$quit\n";
	close HANDLE;

	Any ideas?

Shao.
-- 
____________________________________________________________________________
Shao Zhang - Running Debian 2.1  ___ _               _____
Department of Communications    / __| |_  __ _ ___  |_  / |_  __ _ _ _  __ _ 
University of New South Wales   \__ \ ' \/ _` / _ \  / /| ' \/ _` | ' \/ _` |
Sydney, Australia               |___/_||_\__,_\___/ /___|_||_\__,_|_||_\__, |
Email: shao@cia.com.au                                                  |___/ 
_____________________________________________________________________________


------------------------------

Date: Sat, 19 Aug 2000 15:12:00 GMT
From: marcel@codewerk.com (Marcel Grunauer)
Subject: Re: using perl to interact with a telnet session
Message-Id: <slrn8pt8sf.5jl.marcel@gandalf.local>

On 20 Aug 2000 00:59:40 +1000, Shao Zhang <shao@cia.com.au> wrote:

>	I am trying to use perl to do the following equivalent. But my
>	program does not work. Any one give me some hints??


"Does not work" is a vague description. Next time, please specifically
state what you wanted it to do, what it did or did not do.


>In perl,
>	open(HANDLE, "|telnet $server");
>	sleep 3; print HANDLE "$username\n";
>	sleep 2; print HANDLE "$passwd\n";
>	sleep 2; print HANDLE "$message\n";
>	sleep 2; print HANDLE "$quit\n";
>	close HANDLE;
>
>	Any ideas?


Generally, to do something like that, you'd use the Expect module
(available on CPAN)?

However, in this case, there's something better: Net::Telnet, also
available on CPAN.


-- 
Marcel Gr\"unauer - Codewerk plc . . . . . . . . . . . <http://www.codewerk.com>
Perl Consulting, Programming, Training, Code review . . .  <marcel@codewerk.com>
mod_perl, XML solutions - email for consultancy availability
sub AUTOLOAD{($_=$AUTOLOAD)=~s;^.*::;;;y;_; ;;print} Just_Another_Perl_Hacker();


------------------------------

Date: Sat, 19 Aug 2000 15:11:46 GMT
From: nvp@spamnothanks.speakeasy.org (NP)
Subject: Re: using perl to interact with a telnet session
Message-Id: <Ssxn5.491949$MB.7489325@news6.giganews.com>

On 20 Aug 2000 00:59:40 +1000, Shao Zhang <shao@cia.com.au> wrote:
: 
: In perl,
: 	open(HANDLE, "|telnet $server");

This won't work for you, I think.

I'd suggest the Net::Telnet and/or Expect[.pm] modules.

-- 
Nate II


------------------------------

Date: 16 Sep 99 21:33:47 GMT (Last modified)
From: Perl-Users-Request@ruby.oce.orst.edu (Perl-Users-Digest Admin) 
Subject: Digest Administrivia (Last modified: 16 Sep 99)
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: The mail to news gateway, and thus the ability to submit articles
| through this service to the newsgroup, has been removed. I do not have
| time to individually vet each article to make sure that someone isn't
| abusing the service, and I no longer have any desire to waste my time
| dealing with the campus admins when some fool complains to them about an
| article that has come through the gateway instead of complaining
| to the source.

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 V9 Issue 4067
**************************************


home help back first fref pref prev next nref lref last post