[7795] in Perl-Users-Digest

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

Perl-Users Digest, Issue: 1420 Volume: 8

daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Fri Dec 5 20:08:28 1997

Date: Fri, 5 Dec 97 17:01:44 -0800
From: Perl-Users Digest <Perl-Users-Request@ruby.OCE.ORST.EDU>
To: Perl-Users@ruby.OCE.ORST.EDU (Perl-Users Digest)

Perl-Users Digest           Fri, 5 Dec 1997     Volume: 8 Number: 1420

Today's topics:
     Question about the =~ operator <herselman@pixie.co.za.com>
     Re: Question about the =~ operator (brian d foy)
     Re: Resource Kit Anomaly (Nathan V. Patwardhan)
     Re: Resource Kit Anomaly (Brian Jepson)
     Retrieving keys/values from %param in creating order? <chenyang@mashie.ece.jhu.edu>
     Re: Retrieving keys/values from %param in creating orde <rjk@coos.dartmouth.edu>
     Re: returning an associated array from a perl library <rjk@coos.dartmouth.edu>
     Re: returning an associated array from a perl library <zenin@best.com>
     Re: returning an associated array from a perl library (brian d foy)
     Re: sub in .pm!!!!! <zenin@best.com>
     Re: Tk and Lwp under Activeware (Philip)
     Re: Tk and Lwp under Activeware (Gurusamy Sarathy)
     Re: Wrapping Text in Forms? (Martien Verbruggen)
     Digest Administrivia (Last modified: 8 Mar 97) (Perl-Users-Digest Admin)

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

Date: Fri, 5 Dec 1997 04:51:38 +0200
From: "Richard C. Herselman" <herselman@pixie.co.za.com>
Subject: Question about the =~ operator
Message-Id: <34876c32.0@hawk.pix.za>

This is a multi-part message in MIME format.

------=_NextPart_000_0020_01BD0139.78E55120
Content-Type: text/plain;
	charset="iso-8859-1"
Content-Transfer-Encoding: quoted-printable

Hey y'all

I was wondering if it's possible to match one string with another =
without using the match operator (=3D~), because when I use the match =
operator, like this:

if ($somestring =3D~ /abc/) {  # or whatever
        something;
        something;
        something;
}

 ... the value of $something gets changed to whatever was matched, and I =
don't wanna do that, I just wanna evaluate whether /abc/ is in =
$something, and if it is, then I want the stuff in the if block =
(something, something and something) to be executed. I don't want to =
change the $something variable.

I know I can have something like this:

$oldsomething =3D $something; # copy the variable into another one for =
later use
if ($something =3D=3D /abc/) {  # or whatever
      something;
      something;
      something;
}
#use $oldsomething somewhere down here, when and if needed
=20
 ....but I was thinking something more in the general direction of:

if ($something =3D=3D /abc/) {  # or eq instead of =3D=3D, maybe?
      something;
      something;
      something;
}

Is this possible?

I hope you understand the question...

Thank you for your time.

>> When replying by email, please remove the trailing ".com". <<

------=_NextPart_000_0020_01BD0139.78E55120
Content-Type: text/html;
	charset="iso-8859-1"
Content-Transfer-Encoding: quoted-printable

<!DOCTYPE HTML PUBLIC "-//W3C//DTD W3 HTML//EN">
<HTML>
<HEAD>

<META content=3Dtext/html;charset=3Diso-8859-1 =
http-equiv=3DContent-Type>
<META content=3D'"MSHTML 4.71.2016.0"' name=3DGENERATOR>
</HEAD>
<BODY bgColor=3D#ffffff>
<DIV><FONT color=3D#000000 face=3DArial size=3D2>Hey y'all</FONT></DIV>
<DIV><FONT color=3D#000000 face=3DArial size=3D2></FONT>&nbsp;</DIV>
<DIV><FONT color=3D#000000 face=3DArial size=3D2>I was wondering if it's =
possible to=20
match one string with another without using the match operator (=3D~), =
because=20
when I use the match operator, like this:</FONT></DIV>
<DIV><FONT color=3D#000000 face=3DArial size=3D2></FONT>&nbsp;</DIV>
<DIV><FONT color=3D#000000 face=3DArial size=3D2>if ($somestring =3D~ =
/abc/) {&nbsp; #=20
or whatever</FONT></DIV>
<DIV><FONT color=3D#000000 face=3DArial=20
size=3D2>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; =
something;</FONT></DIV>
<DIV><FONT color=3D#000000 face=3DArial=20
size=3D2>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; =
something;</FONT></DIV>
<DIV><FONT color=3D#000000 face=3DArial=20
size=3D2>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; =
something;</FONT></DIV>
<DIV><FONT color=3D#000000 face=3DArial size=3D2>}</FONT></DIV>
<DIV><FONT color=3D#000000 face=3DArial size=3D2></FONT>&nbsp;</DIV>
<DIV><FONT color=3D#000000 face=3DArial size=3D2>... the value of =
$something gets=20
changed to whatever was matched, and I don't wanna do that, I just wanna =

evaluate whether /abc/ is in $something, and if it is, then I want the =
stuff in=20
the if block (something, something and something) to be executed. I =
don't want=20
to change the $something variable.</FONT></DIV>
<DIV><FONT color=3D#000000 face=3DArial size=3D2></FONT>&nbsp;</DIV>
<DIV><FONT face=3DArial size=3D2>I know I can have something like =
this:</FONT></DIV>
<DIV><FONT face=3DArial size=3D2></FONT>&nbsp;</DIV>
<DIV><FONT color=3D#000000 face=3DArial size=3D2>$oldsomething =3D =
$something; # copy=20
the variable into another one for later use</FONT></DIV>
<DIV><FONT color=3D#000000 face=3DArial size=3D2></FONT><FONT =
face=3DArial size=3D2>
<DIV><FONT color=3D#000000 face=3DArial size=3D2>if ($something =3D=3D =
/abc/) {&nbsp; # or=20
whatever</FONT></DIV>
<DIV><FONT color=3D#000000 face=3DArial =
size=3D2>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;=20
something;</FONT></DIV>
<DIV><FONT color=3D#000000 face=3DArial =
size=3D2>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;=20
something;</FONT></DIV>
<DIV><FONT color=3D#000000 face=3DArial =
size=3D2>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;=20
something;</FONT></DIV>
<DIV><FONT face=3DArial size=3D2>}</FONT></DIV>
<DIV><FONT face=3DArial size=3D2></FONT>#use $oldsomething somewhere =
down here, when=20
and if needed&nbsp;</DIV>
<DIV>&nbsp;</DIV></FONT></DIV>
<DIV><FONT color=3D#000000 face=3DArial size=3D2>....but I was thinking =
something more=20
in the general direction of:</FONT></DIV>
<DIV><FONT color=3D#000000 face=3DArial size=3D2></FONT>&nbsp;</DIV>
<DIV><FONT color=3D#000000 face=3DArial size=3D2>if ($something =3D=3D =
/abc/) {&nbsp; # or=20
eq instead of =3D=3D, maybe?</FONT></DIV>
<DIV><FONT color=3D#000000 face=3DArial size=3D2></FONT><FONT =
color=3D#000000 face=3DArial=20
size=3D2>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; something;</FONT></DIV>
<DIV><FONT color=3D#000000 face=3DArial =
size=3D2>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;=20
something;</FONT></DIV>
<DIV><FONT color=3D#000000 face=3DArial =
size=3D2>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;=20
something;</FONT></DIV>
<DIV><FONT face=3DArial size=3D2>}</FONT></DIV>
<DIV><FONT face=3DArial size=3D2></FONT>&nbsp;</DIV>
<DIV><FONT face=3DArial size=3D2>Is this =
possible?<BR></FONT>&nbsp;</DIV>
<DIV><FONT face=3DArial size=3D2>I hope you understand the =
question...</FONT></DIV>
<DIV><FONT face=3DArial size=3D2></FONT>&nbsp;</DIV>
<DIV><FONT face=3DArial size=3D2>Thank you for your time.</FONT></DIV>
<DIV><FONT face=3DArial size=3D2></FONT>&nbsp;</DIV>
<DIV><FONT face=3DArial size=3D2>&gt;&gt; When replying by email, please =
remove the=20
trailing &quot;.com&quot;. &lt;&lt;</FONT></DIV></BODY></HTML>

------=_NextPart_000_0020_01BD0139.78E55120--



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

Date: Thu, 04 Dec 1997 23:06:52 -0500
From: comdog@computerdog.com (brian d foy)
Subject: Re: Question about the =~ operator
Message-Id: <comdog-ya02408000R0412972306520001@news.panix.com>

In article <34876c32.0@hawk.pix.za>, "Richard C. Herselman" <herselman@pixie.co.za.com> wrote:

>This is a multi-part message in MIME format.

[ oy - this is some seriously broken stuff
X-Newsreader: Microsoft Outlook Express 4.71.1712.3
X-MimeOLE: Produced By Microsoft MimeOLE V4.71.1712.3
]

>I was wondering if it's possible to match one string with another =
>without using the match operator (=3D~), because when I use the match =
>operator, like this:
>
>if ($somestring =3D~ /abc/) {  # or whatever

>}

>... the value of $something gets changed to whatever was matched, and I =
>don't wanna do that, I just wanna evaluate whether /abc/ is in =
>$something, and if it is, then I want the stuff in the if block =
>(something, something and something) to be executed. I don't want to =
>change the $something variable.

the matching operator does not change whatever it is bound to.  the 
substitution and translation operators will.  in your example,
$somestring remains the same.

perhaps you could post the actual code with which you have a problem?
there might be other problems...

of course, you could also do something like

   $other_string = $some_string;

   if( $other_string =~ /$pattern/ ) { ... }

but that's kinda pointless.

good luck :)

-- 
brian d foy                                  <comdog@computerdog.com>
NY.pm - New York Perl M((o|u)ngers|aniacs)*  <URL:http://ny.pm.org/>
CGI Meta FAQ <URL:http://computerdog.com/CGI_MetaFAQ.html>


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

Date: 5 Dec 1997 02:32:42 GMT
From: nvp@shore.net (Nathan V. Patwardhan)
Subject: Re: Resource Kit Anomaly
Message-Id: <667p4a$oii@fridge.shore.net>

Peter J. Schoenster (pschon@baste.magibox.net) wrote:

: Why do they not tell us what is in the book(s)?  I wonder if O'Reilly
: has the source code on their website?  It seems that O'Reilly is
: putting less and less of their books on the web.  I bet someone
[snip]

There will be a TOC and chapters from some of the books on the ORA
website in the near future.  I'll be putting up the source code at
that time.  Someone is working on these materials as we speak
(figuratively, of course).

Hope this helps.

--
Nathan V. Patwardhan
please don't send spam to pres@whitehouse.gov


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

Date: 5 Dec 1997 03:33:09 GMT
From: bjepson@ids.net (Brian Jepson)
Subject: Re: Resource Kit Anomaly
Message-Id: <slrn68eteg.c85.bjepson@gelvis.ids.net>

In article <3481eb7f.91385475@news.magibox.net>, Peter J. Schoenster wrote:

[...]

>
>All I want to know is what is in the book before I buy it.  "A whole
>bunch of good modules" just doesn't cut it.  I don't need a FIXED
>version of CPAN; I much prefer the live online version.  If this book
>is just a snapshot of CPAN then I have to ask why have the internet?
>

[...]

Actually, CPAN.pm plays very well with CD-ROM mirrors of CPAN. Not only
will it install modules from the CD (which is to be expected), but if 
you configure it properly, it will use a remote CPAN site for getting
index files, rather than the CD. Then, when you try to install the latest 
module, it will optimistically check the CD first, and if it doesn't find 
it, it will roll over to the remote CPAN site in your urllist.

CPAN.pm will try to get modules from file:// URLs first, no matter where
they appear in the urllist. From the CPAN manpage:

  So the recommendation for the owner of a CD-ROM with CPAN
  contents is: include your local, possibly outdated CD-ROM as
  a file URL at the end of urllist

This is very nice for those of us who are still limping along with 
modems :-)

-- 
Brian Jepson * (bjepson@ids.net) * http://users.ids.net/~bjepson


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

Date: Tue, 02 Dec 1997 10:22:40 -0500
From: Chenyang Xu <chenyang@mashie.ece.jhu.edu>
Subject: Retrieving keys/values from %param in creating order?
Message-Id: <348427C0.41C6@mashie.ece.jhu.edu>

Hello,

   I am wondering how to retrieve keys/values pair from associate array
say %param in the order they are created.

   Thanks for any suggestions and help.

-- 
C. Xu


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

Date: Thu, 04 Dec 1997 21:59:12 -0500
From: Chipmunk <rjk@coos.dartmouth.edu>
Subject: Re: Retrieving keys/values from %param in creating order?
Message-Id: <34876DFF.A6CE88C6@coos.dartmouth.edu>

Chenyang Xu wrote:
> 
> Hello,
> 
>    I am wondering how to retrieve keys/values pair from associate array
> say %param in the order they are created.

Keep an array containing the names of the keys.

Every time you add a pair to the hash:

push(@hashkeys, $key) unless exists $hash{$key};   # pushes the key onto the array
                                                   #   unless the key was
already in the hash
%hash{$key} = $value;

When you want to get the pairs in the order they were created:

foreach $key (@hashkeys) {
  $value = $hash{$key};
}

Chipmunk


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

Date: Thu, 04 Dec 1997 21:54:40 -0500
From: Chipmunk <rjk@coos.dartmouth.edu>
Subject: Re: returning an associated array from a perl library
Message-Id: <34876CEF.2A5D8575@coos.dartmouth.edu>

Katie wrote:
> 
>         Hi,
> 
>         I am building a perl library for use with numerous files. I am using an
> include statement to include the files. In one of the library files there
> is a function that I need to get to return an associated array to the
> program that is calling the library file. Could anyone offer any
> suggestions on the syntax etc. to use to get the array to return in full??

return @array;

Or, if you meant associative array:

return %array;

Chipmunk


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

Date: 5 Dec 1997 03:06:47 GMT
From: Zenin <zenin@best.com>
Subject: Re: returning an associated array from a perl library
Message-Id: <881291373.64142@thrush.omix.com>

Katie <katie@irenyx.com> wrote:
: In one of the library files there
: is a function that I need to get to return an associated array to the
: program that is calling the library file.

	sub foo {
	    my %hash = qw(this that foo bar);
	    return %hash;
	}

	my %myHash = foo ();

-- 
-Zenin
 zenin@best.com


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

Date: Thu, 04 Dec 1997 23:20:02 -0500
From: comdog@computerdog.com (brian d foy)
Subject: Re: returning an associated array from a perl library
Message-Id: <comdog-ya02408000R0412972320020001@news.panix.com>

In article <01bd017a$264c1480$130232cc@univac.irenyx.com>, "Katie" <katie@irenyx.com> wrote:

>        I am building a perl library for use with numerous files. I am using an
>include statement to include the files. In one of the library files there
>is a function that I need to get to return an associated array to the
>program that is calling the library file. Could anyone offer any
>suggestions on the syntax etc. to use to get the array to return in full?? 


i have this bias against passing arrays and hashes about, so unless there
is a compelling reason not to, i tend to pass references:

   use subs qw(foo bar);

   #pass a hash reference
   foo(\%hash);

   #pass an array reference
   bar(\@array);

   #things you do in here affect %hash
   sub foo { my $hash_ref = shift;  ...; }

   #things you do in here affect @array
   sub bar { my $array_ref = shift; ...; }

you can also return references.

this sort of thing tends to saves lots of overhead passing large data
structures by value, which could involve lots of copying and memory use.

YMMV.

-- 
brian d foy                                  <comdog@computerdog.com>
NY.pm - New York Perl M((o|u)ngers|aniacs)*  <URL:http://ny.pm.org/>
CGI Meta FAQ <URL:http://computerdog.com/CGI_MetaFAQ.html>


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

Date: 5 Dec 1997 02:59:47 GMT
From: Zenin <zenin@best.com>
Subject: Re: sub in .pm!!!!!
Message-Id: <881290952.591905@thrush.omix.com>

James Dornan <james@zaire.hooked.net> wrote:
: I created my first sub in a pm file and I wanted to use it to set all
: kinds of variables. Unlike a sub from withing the script, it does not
: share variale space. How do I change this?

	Hmm, I really hate to tell you because it's bound to only lead you
	down a path of bad habits, but here ya go:

		$main::SomeMainGlobal = 'foobar';

	or, you can export stuff, which is better because it doesn't assume
	to know the calling package the way the above does:

		package Foo;
		require Exporter;
		@ISA    = qw(Exporter);
		@EXPORT = qw($Foo $Bar);
		$Foo = 'foo';
		$Bar = 'bar';

-- 
-Zenin
 zenin@best.com


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

Date: Fri, 05 Dec 1997 03:39:56 GMT
From: fil_nospam@login.net (Philip)
Subject: Re: Tk and Lwp under Activeware
Message-Id: <34877736.331566@nntphost.login.net>

On 4 Dec 1997 11:59:58 -0800, mcravit@best.com (Matthew Cravit) wrote:

>In article <34860f4c.13737984@news.ntslink.net>,
>David Grove <dgrove@ntslink.net> wrote:
>>Is there a port of Tk to Activeware. I need 310 for the perl2exe
>>'compiler'. Also... same question for LWP.
>
>Not for Activeware. However, the Win32 port of Perl by Gurusamy Sarathy (sp?)
>is much better anyway (for example, it actually supports flock), and it
>includes Tk, LWP, and a bunch of other useful modules. You can get it from
>your local CPAN archive under authors/id/GSAR. For a list of CPAN sites,
>go to http://www.perl.com/CPAN/SITES.html.

However, it doesn't do command line file globing (perl script.pl
*.html) .  And asciimode files come out strange, say you have \r\r in
a file... or \r\r\n.

-Philip


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

Date: 5 Dec 1997 04:08:28 GMT
From: gsar@engin.umich.edu (Gurusamy Sarathy)
Subject: Re: Tk and Lwp under Activeware
Message-Id: <667uns$dst@srvr1.engin.umich.edu>

  [ mailed and posted ]

In article <34877736.331566@nntphost.login.net>,
Philip <fil_nospam@login.net> wrote:
>On 4 Dec 1997 11:59:58 -0800, mcravit@best.com (Matthew Cravit) wrote:
>>Not for Activeware. However, the Win32 port of Perl by Gurusamy Sarathy (sp?)
>>is much better anyway (for example, it actually supports flock), and it
>>includes Tk, LWP, and a bunch of other useful modules. You can get it from
>>your local CPAN archive under authors/id/GSAR. For a list of CPAN sites,
>>go to http://www.perl.com/CPAN/SITES.html.
>
>However, it doesn't do command line file globing (perl script.pl
>*.html) .

=head2 Why won't my perl understand wildcards in arguments?

The default command shells on DOS descendant operating systems (such
as they are) usually do not expand wildcard arguments supplied to
programs.  They consider it the application's job to handle that.
This is commonly achieved by linking the application (in our case,
perl) with startup code that the C runtime libraries usually provide.
However, doing that results in incompatible perl versions (since the
behavior of the argv expansion code differs depending on the
compiler, and it is even buggy on some compilers).  Besides, it may
be a source of frustration if you use such a perl binary with an
alternate shell that *does* expand wildcards.

Instead, the following solution works rather well. The nice things
about it: 1) you can start using it right away 2) it is more powerful,
because it will do the right thing with a pattern like */*/*.c
3) you can decide whether you do/don't want to use it 4) you can
extend the method to add any customizations (or even entirely
different kinds of wildcard expansion).

	C:\> copy con c:\perl\lib\Wild.pm
	# Wild.pm - emulate shell @ARGV expansion on shells that don't
	use File::DosGlob;
	@ARGV = map {
		      my @g = File::DosGlob::glob($_) if /[*?]/;
		      @g ? @g : $_;
		    } @ARGV;
	1;
	^Z
	C:\> set PERL5OPT=-MWild
	C:\> perl -le "for (@ARGV) { print }" */*/perl*.c
	p4view/perl/perl.c
	p4view/perl/perlio.c
	p4view/perl/perly.c
	perl5.004_02/win32/perlglob.c
	perl5.004_02/win32/perllib.c
	perl5.004_03/win32/perlglob.c
	perl5.004_03/win32/perllib.c
	perl5.004_531/win32/perlglob.c
	perl5.004_531/win32/perllib.c

Note there are two distinct steps there: 1) You'll have to create
Wild.pm and put it in your perl lib directory. 2) You'll need to
set the PERL5OPT environment variable.  If you want argv expansion
to be the default, just set PERL5OPT in your default startup
environment.

>And asciimode files come out strange, say you have \r\r in
>a file... or \r\r\n.
>

You'll have to be a little more specific than that.  If the Activeware
port strips them and the standard port doesn't, it's most likely a
difference in the compilers used to build the two.  Perl has never
done any explicit stripping of \r's.(*)

 - Sarathy.
   gsar@umich.edu

(*) It might treat \r's just like other whitespace one of these days.
Larry has spoken.




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

Date: 5 Dec 1997 01:54:00 GMT
From: mgjv@comdyn.com.au (Martien Verbruggen)
Subject: Re: Wrapping Text in Forms?
Message-Id: <667mro$bk7$1@comdyn.comdyn.com.au>

In article <3487275A.D30076FF@horizonint.com>,
	Dale Chavez <dchavez@horizonint.com> writes:
> 
> However, when user manually enters a CR in the text form, I get a bogus
> temp file with the name of the new line as the temp file!  What could be
> causing this?  How do I fix?

If you post some code, we can have a look at it, and possibly point out
where it goes wrong.

Martien
-- 
Martien Verbruggen                  | 
Webmaster www.tradingpost.com.au    | I'm just very selective about what I
Commercial Dynamics Pty. Ltd.       | accept as reality - Calvin
NSW, Australia                      | 


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

Date: 8 Mar 97 21:33:47 GMT (Last modified)
From: Perl-Request@ruby.oce.orst.edu (Perl-Users-Digest Admin) 
Subject: Digest Administrivia (Last modified: 8 Mar 97)
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.misc (and this Digest), send your
article to perl-users@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.

The Meta-FAQ, an article containing information about the FAQ, is
available by requesting "send perl-users meta-faq". The real FAQ, as it
appeared last in the newsgroup, can be retrieved with the request "send
perl-users FAQ". Due to their sizes, neither the Meta-FAQ nor the FAQ
are included in the digest.

The "mini-FAQ", which is an updated version of the Meta-FAQ, is
available by requesting "send perl-users mini-faq". It appears twice
weekly in the group, but is not distributed in the digest.

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 V8 Issue 1420
**************************************

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