[7970] in Perl-Users-Digest

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

Perl-Users Digest, Issue: 1595 Volume: 8

daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Wed Jan 7 14:21:00 1998

Date: Wed, 7 Jan 98 11:00:35 -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           Wed, 7 Jan 1998     Volume: 8 Number: 1595

Today's topics:
     arrays as parameters in subroutines <brian@birdsong.cudenver.edu>
     base64encode/decode <uvlarson@avesta.com>
     Re: Calling 'require' on an arbitrary module (Tom Hukins)
     Re: Can I create a Linked List in Perl scott@softbase.com
     Editing Perl question (Manyhats12)
     Embed Perl in Win32 <dstanley@techdev.compuserve.com>
     Re: file glob restrictions?! <joseph@5sigma.com>
     Hash Slice Syntax Question <jhg@austx.tandem.com>
     Integers to Hex in correct network order <tonyc@talex.com>
     Re: Integers to Hex in correct network order (Kerry Schwab)
     Re: Looking for way to download files to browsers using (brian d foy)
     Re: Looking for way to download files to browsers using scott@softbase.com
     Re: Looking for way to download files to browsers using (brian d foy)
     Modularize non object code (Barry G Reville)
     Re: Perl program transfer (Michael Kelly)
     Re: posting urlencoded data with one line (brian d foy)
     Re: printing quotes with print command <jacklam@ulrik.uio.no>
     Prob: Statusbar or how to show parts of a Line before p <sseitz@suk.com>
     Re: Q: search matching "(" and ")" (Ilya Zakharevich)
     Re: sending email (Net::SMTP).. problem <spam@spam.spam>
     Re: serious post about gmtime and year-1900 (was Re: Pe <Russell_Schulz@locutus.ofB.ORG>
     Setting a time limit <dionisio@netscape.com>
     Re: Sorting on the xth position in a ascii file. (Terry Michael Fletcher - PCD ~)
     Re: TEST IF A VALUE EXISTS IN AN ARRAY (Greg Bacon)
     Re: Testing for valid RegExps? (Greg Bacon)
     Re: Trimming blanks <jacklam@ulrik.uio.no>
     Re: unlink return value (M.J.T. Guy)
     Wildcard in  if ( x = a ) ? (Paul Ryder)
     Re: Would yo explain the Perl "pack" command to me? (courtesy)
     Re: Would yo explain the Perl "pack" command to me? (Anthony Mulligan)
     Digest Administrivia (Last modified: 8 Mar 97) (Perl-Users-Digest Admin)

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

Date: Wed, 07 Jan 1998 11:38:46 -0700
From: Brian <brian@birdsong.cudenver.edu>
Subject: arrays as parameters in subroutines
Message-Id: <34B3CBB5.EFBCD1DC@birdsong.cudenver.edu>

I'm trying to send a sub two arrays, but only the first array's values
are being
read.

Here's the code:
($update_statement, $insert_statement, $error_statement) =
&create_stmt($table_name, @values, @column_info);

&create_stmt gets the values for @values but @column_info is empty.

Any ideas and/or suggestions would be greatly appreciated!
Brian






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

Date: Wed, 07 Jan 1998 11:34:10 -0500
From: Usha Vas Larson <uvlarson@avesta.com>
Subject: base64encode/decode
Message-Id: <34B3AE82.D7EF002C@avesta.com>

Hi,

Has anybody written base64encode/decode routine in perl? If so, could
you point me to it. I'm new to perl and realize that it would take me a
while to figure it out, and need it asap.

Thanks,
usha



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

Date: Wed, 07 Jan 1998 18:31:18 GMT
From: tom@NOSPAMeborcom.com (Tom Hukins)
Subject: Re: Calling 'require' on an arbitrary module
Message-Id: <34b3c6cc.94569@nntp.netcom.net.uk>

On 5 Jan 1998 17:39:47 GMT, mjtg@cus.cam.ac.uk (M.J.T. Guy)
wrote:

>Joshua J. Kugler <jkugler@inreach.com> wrote:
>>
>>You could try having your subroutines after your __END__ statement in
>>your Perl code. Then the routines would only be compiled if they are
>>called.  I think.  You might have to double check that.
>
>It would save lots of people round the world time if _you_ double
>checked before posting incorrect information.
>
>For information on how this can actually be done, see
>
>       perldoc perlsub           - the section on Autoloading
>       perldoc SelfLoader
>       perldoc AutoLoader
>       perldoc AutoSplit

Mike,

Thanks for your advice. All these documents are great if you want
to arbitrarily include subroutines in your code. However, I'm
still unsure if I can arbitrarily include packages, which is what
I'd rather do.

My problem (which I probably should have explained better in my
first post) is along the lines of this:

I have an animal, $animal, which needs feeding. If it's a bird
I'll give it seed, if it's a dog I'll give it dog food. However,
there are thousands of animals in the world, and this could be
any one of them. Fortunately, $animal knows what it is; if it's a
dog it contains $animal->{'creature'} contains 'Dog', if it's a
bird $animal->{'creature'} contains 'Bird'.

What my animal feeding code would do is something like this:
	$creature = $animal->{'creature'};
	require "Animal::$creature";
	Animal::$creature->feed($animal);

Each package within Animal::* would contain methods which perform
the same action, but in a different way, such as the different
ways of feeding. This seems a much better way of dealing with
this problem than having one package to deal with all animals.
Also, it would be a bad idea to 'use' or 'require' every single
package because there are many of them. It would be best to only
use them as and when they are needed.

However, the code above would not work because require doesn't
like package names like "Animal::$creature::. So, my question is,
is it possible to do anything like this?

Thanks for your time,
Tom


If you want to e-mail me remove 'NOSPAM' from my address

-- 
       Learn how to create amazing web sites

     Visit eBORcOM's Web Development Resources
          http://www.eborcom.com/webmaker/


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

Date: 7 Jan 1998 15:11:20 GMT
From: scott@softbase.com
Subject: Re: Can I create a Linked List in Perl
Message-Id: <6905uo$v52$1@mainsrv.main.nc.us>

draggs@hawkeye.idx.com writes:

>I was wondering if it was possible to create a c-style
> linked list and perl.

The great thing about Perl is you don't have to! All the
data structures in Perl are totally dynamic. Arrays magically
resize themselves, and make it easy to insert and delete
from themselves. Arrays *are* linked lists in Perl, with 
a very high level syntax!

Scott
--
Look at Softbase Systems' client/server tools, www.softbase.com
Check out the Essential 97 package for Windows 95 www.skwc.com/essent
All my other cool web pages are available from that site too!
My demo tape, artwork, poetry, The Windows 95 Book FAQ, and more. 


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

Date: 7 Jan 1998 18:35:52 GMT
From: manyhats12@aol.com (Manyhats12)
Subject: Editing Perl question
Message-Id: <19980107183501.NAA01421@ladder02.news.aol.com>

Is it possible to use notepad in Windows to edit a cgi script written in Perl?
I know that there should not be any carrige returns, but if it is saved as a
text file, with editing done only between the lines, would it be a problem?
Thank you in advance!
-Leslie


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

Date: Wed, 7 Jan 1998 11:25:41 -0500
From: "J. Donavan Stanley" <dstanley@techdev.compuserve.com>
Subject: Embed Perl in Win32
Message-Id: <u56FNk4G9GA.186@nih2naab.prod2.compuserve.com>

I'm trying to embed Perl within a C++ program I'm developing.  I know the
Unix distributions include instructions on how to do it on that platform but
I can't seem to find info for Win32.

Can anyone give me a pointer to a howto?

Donavan Stanley
CompuServe Inc.




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

Date: Wed, 07 Jan 1998 11:04:36 -0700
From: "Joseph N. Hall" <joseph@5sigma.com>
Subject: Re: file glob restrictions?!
Message-Id: <34B3C3A5.458EC8AC@5sigma.com>

It's a C shell limit.  Use readdir.

	-joseph
	 http://www.effectiveperl.com

Jakob Fix wrote:
> 
> I try this
> 
> @files = <*.sgm>;
> 
> to read almost 2000 file names in this array, but it doesn't work.


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

Date: Wed, 07 Jan 1998 09:53:04 -0600
From: James Garrison <jhg@austx.tandem.com>
Subject: Hash Slice Syntax Question
Message-Id: <34B3A4E0.CB5B61B6@austx.tandem.com>

>From Blue Camel p.37 we have the syntax for a
slice of a hash:

	%a=("One"=>1, "Two"=>2, "Three"=>3);
	print "@a{One,Three}\n";

	1 3

This all makes sense.  Now do it with a hash ref:

	$b=\%a;
	print $b->{Two};

	2

so far so good, BUT:

	print @$b->{Two,Three};

        Not an ARRAY reference at (eval 136) line 2.

instead:

	print "@$b{Two,Three}\n";

	2 3

Why does this not require arrow notation?  Is this a syntactical
wart, or does it follow from some other rule I'm not aware of?

Waiting to be enlightened......

-- 
James Garrison			mailto:jhg@austx.tandem.com
Tandem Computers, Inc
14231 Tandem Blvd, Rm 1038	Phone: (512) 432-8455
Austin, TX 78728-6699		Fax:   (512) 432-8247


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

Date: Wed, 07 Jan 1998 07:50:32 -0800
From: Tony Chilton <tonyc@talex.com>
Subject: Integers to Hex in correct network order
Message-Id: <34B3A448.254AD60D@talex.com>

I am writing a script that emulates a piece of network hardware. I need
to represent integers in the proper hex order across the network from a
SUN to a PC. So... if i have the number 300 (0x12c) it needs to be seen
in the network packet as "2C 01" not "01 2C". How do I do this? I think
I should be using pack or unpack but I have been unable to figure out
how despite hours of futzing with it.


Any help would be appreciated.
If you could e-mail me your answer that would be most helpful.

TIA
TonyC

tonyc@talex.com





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

Date: 7 Jan 1998 09:22:20 -0700
From: kschwab@nyx.net (Kerry Schwab)
Subject: Re: Integers to Hex in correct network order
Message-Id: <690a3s$5vc$1@nyx10.nyx.net>

In article <34B3A448.254AD60D@talex.com>,
Tony Chilton  <tonyc@talex.com> wrote:
>I am writing a script that emulates a piece of network hardware. I need
>to represent integers in the proper hex order across the network from a
>SUN to a PC. So... if i have the number 300 (0x12c) it needs to be seen
>in the network packet as "2C 01" not "01 2C". How do I do this? I think
>I should be using pack or unpack but I have been unable to figure out
>how despite hours of futzing with it.
>

Maybe you are thinking about it too hard :)

(from the format specifiers section for pack in 'perldoc perlfunc')

n   A short in "network" (big-endian) order.
N   A long in "network" (big-endian) order. 
v   A short in "VAX" (little-endian) order.
V   A long in "VAX" (little-endian) order.

$ perl -e '$foo=pack("v",300);print $foo' > file
$ ~kschwab/bin/hdump file
00000000   2c01                                  ,.
$ perl -e '$foo=pack("n",300);print $foo' > file
$ ~kschwab/bin/hdump file
00000000   012c                                  .,


--
Kerry

>
>Any help would be appreciated.
>If you could e-mail me your answer that would be most helpful.
>
>TIA
>TonyC
>
>tonyc@talex.com
>
>
>




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

Date: Wed, 07 Jan 1998 11:13:38 -0500
From: comdog@computerdog.com (brian d foy)
Subject: Re: Looking for way to download files to browsers using PERL
Message-Id: <comdog-ya02408000R0701981113380001@news.panix.com>
Keywords: from just another new york perl hacker

In article <68uk2s$79b$2@winter.news.erols.com>, wcb4@erols.com posted:

>>&sendfile # to call the routine to send the file
>should be &sendfile; (forgot the semi)
>>
>>
>>sub sendfile {
>>    print "application/octet-stream\n\n"; #header for executable files
>        should read print "Content: application/............" forgot


the proper HTTP header is Content-type.

but don't forget about Content-length and all the other things a 
well behave HTTP agent should send.

-- 
brian d foy                                  <comdog@computerdog.com>
Fifth Avenue Disaster! <URL:http://computerdog.com/brian/fire/>
CGI Meta FAQ <URL:http://computerdog.com/CGI_MetaFAQ.html>


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

Date: 7 Jan 1998 15:14:58 GMT
From: scott@softbase.com
Subject: Re: Looking for way to download files to browsers using PERL
Message-Id: <69065i$v52$2@mainsrv.main.nc.us>

Juan Vega (juan@vibrant.com) wrote:
> 3) CGI script sends *.exe to browser such that browser
> asks user where file
> should be saved (big problem - I am lost)

CGI itself can't do this!!! You can't inflict a file download
on a user. There's no way.

What you can do is provide a link to the file, and the user can choose
to download it by clicking the link. Even this is fraught with peril
because EXE files may not survive the trip from server to browser
because of improper MIME type setup.  I've tried to do that before and
have wound up creating zip files for everything because the EXE doesn't
make the trip.

Scott
--
Look at Softbase Systems' client/server tools, www.softbase.com
Check out the Essential 97 package for Windows 95 www.skwc.com/essent
All my other cool web pages are available from that site too!
My demo tape, artwork, poetry, The Windows 95 Book FAQ, and more. 


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

Date: Wed, 07 Jan 1998 12:26:34 -0500
From: comdog@computerdog.com (brian d foy)
Subject: Re: Looking for way to download files to browsers using PERL
Message-Id: <comdog-ya02408000R0701981226340001@news.panix.com>
Keywords: from just another new york perl hacker

In article <69065i$v52$2@mainsrv.main.nc.us>, scott@softbase.com posted:

>Juan Vega (juan@vibrant.com) wrote:
>> 3) CGI script sends *.exe to browser such that browser
>> asks user where file
>> should be saved (big problem - I am lost)
>
>CGI itself can't do this!!! You can't inflict a file download
>on a user. There's no way.

i've done it for several clients.  it's a fairly trivial task.
the persons in comp.infosystems.www.authoring.cgi might even tell
you how to do it if you ask nicely.

-- 
brian d foy                                  <comdog@computerdog.com>
Fifth Avenue Disaster! <URL:http://computerdog.com/brian/fire/>
CGI Meta FAQ <URL:http://computerdog.com/CGI_MetaFAQ.html>


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

Date: 7 Jan 1998 16:58:17 GMT
From: breville@uoguelph.ca (Barry G Reville)
Subject: Modularize non object code
Message-Id: <690c79$n6c@ccshst05.uoguelph.ca>

	I have written a non object perl program that works fine but I 
would like to modularize it for maintainability and reusability.  There 
are many subroutines - many that I use multiple times.  Some of these are 
general utilities that I would like to keep all in one file and somehow 
be able to call the subroutines like normal.
	Is this possible, and if so how?

Thanks in advance,

Barry Reville 
University of Guelph
Computing and Communications Services
breville@uoguelph.ca
www.uoguelph.ca/~breville


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

Date: Wed, 07 Jan 1998 16:54:05 GMT
From: mkelly99@NOSPAMgate.net (Michael Kelly)
Subject: Re: Perl program transfer
Message-Id: <34b7ab0c.3354613@news.gate.net>

On Wed, 07 Jan 1998 08:43:27 -0500, Scott Vetter <svetter@ameritech.net> wrote:

>I transfer Perl programs between my OS/2 system and a UNIX system. 
>From OS/2 to UNIX the Perl program has a "^M" on the end of each line. 
>And from UNIX to OS/2, lines run together.  Is there a Perl program out
>there that will strip the "^M"'s at the end of each line and put it back
>on the OS/2 system?

To remove the carriage returns:
perl -pe 's/\r\n/\n/g' oldfile >newfile

To add the carriage returns:
#perl script to add <CR>s while filtering stdin to stdout
while(<>)  {
  chop;
  print "$_ \r\n";
}



Mike

"Genius gives birth, talent delivers."

                - Jack Kerouac

(remove NOSPAM from address, if present, to reply)


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

Date: Wed, 07 Jan 1998 11:21:06 -0500
From: comdog@computerdog.com (brian d foy)
Subject: Re: posting urlencoded data with one line
Message-Id: <comdog-ya02408000R0701981121060001@news.panix.com>
Keywords: from just another new york perl hacker

In article <34b31d2e.962508@news.cyberhighway.net>, erudite@cyberhighway.net (Chris Johnston) posted:

>  Hi, although this application is with C++ I thought you people would
>know much more on this subject. Any way, in this app it involves
>posting data through a single line, instead of going to the page and
>typing it in myself.
>  For example, if there is a text area and a text box how can you get
>that in a "http://www" type of format and posting it that way. This is
>somewhat of a last resort so any replies will be greatly appreciated.

perhaps you should reform your question to clarify that task which
you are attempting, then post to a C++ newsgroup.  Doing things in
C++ is not the same as in Perl.  furthermore, the libraries involved
probably have different APIs.

from what i can tell, you have two data that you want to put 
together.  forget about where these data came from or where they
are going - that should simply your problem.

-- 
brian d foy                                  <comdog@computerdog.com>
Fifth Avenue Disaster! <URL:http://computerdog.com/brian/fire/>
CGI Meta FAQ <URL:http://computerdog.com/CGI_MetaFAQ.html>


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

Date: Wed, 07 Jan 1998 19:40:03 +0100
From: "Peter J. Acklam" <jacklam@ulrik.uio.no>
Subject: Re: printing quotes with print command
Message-Id: <34B3CC02.794B@ulrik.uio.no>

Malcolm Hoar wrote:
> "Peter J. Acklam" <jacklam@ulrik.uio.no> wrote:
> > Glen Bell wrote:
> > >
> > > print NEWFILE "  <body bgcolor="#FFFFFF"
> > background="../backgrounds/ruff.jpg">";
> >
> >print NEWFILE "  <body bgcolor='#FFFFFF'
> >background='../backgrounds/ruff.jpg'>";
> 
> Not really on-topic here but:
> 
> 1. Using single quotes in tags is not in compliance with
>    the HTML specs and:

Since we're at it, let me quote the HTML 3.2 spec
(http://www.w3.org/TR/REC-html32.html)

  Attribute values can be quoted using double or single
  quote marks (ASCII decimal 34 and 39 respectively).
 
> 2. Simply doesn't work with all browsers (e.g. Netscape 1.2).

People using Netscape 1.2 should do the same as those
using Perl 4. Upgrade.

Peter


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

Date: Wed, 07 Jan 1998 17:13:50 +0100
From: Stephan Seitz <sseitz@suk.com>
Subject: Prob: Statusbar or how to show parts of a Line before printing Return
Message-Id: <34B3A9BE.B9B9F79A@suk.com>

Hello!

I have a problem under Linux or Unix:
How can I print parts of a Line (and make them visible!) using a
Perl-Script befor printing the Return?

Yours
  Stephan


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

Date: 7 Jan 1998 18:00:21 GMT
From: ilya@math.ohio-state.edu (Ilya Zakharevich)
Subject: Re: Q: search matching "(" and ")"
Message-Id: <690frl$5lq$1@mathserv.mps.ohio-state.edu>

[A complimentary Cc of this posting was sent to 
<tobez@plab.ku.dk>],
who wrote in article <34B37663.F53@plab.ku.dk>:
> Ilya Zakharevich wrote:
> 
> > > : Q: How can I  easily find  the matching parir for "(" and ")" for A1?
> > >
> > > You can't do it 'easily' (at least accordning to my own 'easiness'
> > > metric).  Just to save you some pointless hacking, you can't do it for
> > > arbitrary levels of nesting using regexes
> > 
> > Yes you can with the latest RE engine, one of the tests in t/op/pat.t
> > is doing exactly this.  But this is still not "easily" - though very
> > quick.  To make it "easy" several other changes to RE engine should
> > materialize first.
> 
> 8-O
> t/op/pat.t from which version of Perl?
> And which particular test?  I could not find it in my copy
> from 5.004_04...

In _55 and more it is near string "matchit".

Ilya


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

Date: Wed, 07 Jan 1998 17:14:08 +0000
From: catty <spam@spam.spam>
Subject: Re: sending email (Net::SMTP).. problem
Message-Id: <34B3B7E0.1AB1AB71@spam.spam>

Graham Barr wrote:

> Net::SMTP implements the SMTP protocol, the header lines are not
> part of the protocol itself, although they are part of the
> standard for sending mail.

The sender is responsible for (but need not) adding "To:" "From:"
"Subject:" etc. lines to the header. NOT the received-from line,
that is the responsibility of the receiving side. All reputable ISPs
do add the received-from line, and any other such information about
the sender; it looks like this:

Received: from xxx.xxxxxx.net ([111.111.111.111])

Note that the sender's IP address is captured by the recv ISP so the
recipient can decide to filter on that information. It is NOT something
controllable or fakeable (easily) by the sender. There may be additional
phony received-from lines added by spammers, so you can only trust
the last one (which is placed on top).

> You are obviously trying so hard to flame people you are not thinking
> straight.

You can't seem to resist such cheap shots, can you?

Originally, I showed a sample that sends mail, and you flamed it
for no apparent logical reason. Perhaps you did not realize that
the received-from line is added by the receiving end, not the sender.


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

Date: Wed, 7 Jan 1998 13:44:35 +0000
From: Russell Schulz <Russell_Schulz@locutus.ofB.ORG>
Subject: Re: serious post about gmtime and year-1900 (was Re: Perl not Y2K compliant)
Message-Id: <19980107.134435.1y6.rnr.w164w@locutus.ofB.ORG>

pudge@pobox.com (Chris Nandor) writes:

>>> [sample proof-it-works-on-my-system code deleted]
>> 
>> this might be a good thing to put in the documentation, instead of a
>> `trust me it will work' style claim.
>
> Can't you figure that code out for yourself?

I don't understand the assumption behind your question.  I'll be
more verbose, and see if that removes any assumptions:

I think that instead of the perl documentation saying ``it will just
work, trust me'', it could say

  this unfortunate definition comes from the ANSI C standard, so it
  will work in perl, as long as the C runtime library was correctly
  implemented when perl was compiled.  if you need to test your system,
  run this code [...], which will show this [...]:

> I don't see what the difficulty is.
> Programming is an empirical science.

try it, and see if it looked like it worked, and if it didn't, mess
with it until it does, and then hope it always will...

huh.
-- 
Russell_Schulz@locutus.ofB.ORG  Shad 86c


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

Date: Wed, 07 Jan 1998 08:37:29 -0800
From: "Patrick-James H. Dionisio" <dionisio@netscape.com>
Subject: Setting a time limit
Message-Id: <34B3AF49.AC7C0F23@netscape.com>

Is there a way in Perl to set a time limit on running shell programs?
Let's say I'd like a script to allow a program 30 seconds to 
execute, terminate the program and then move on.

I'm using Perl 5.001 on WinNT and it looks like the alarm function 
is not supported in this version.  Anybody know if later versions
support alarm or has another way of setting time limits?

Thanks in advance.



-->Patrick


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

Date: 7 Jan 1998 16:37:37 GMT
From: tfletche@pcocd2.intel.com (Terry Michael Fletcher - PCD ~)
Subject: Re: Sorting on the xth position in a ascii file.
Message-Id: <690b0h$pf3$1@news.fm.intel.com>

Jan Van den heuvel (jan@skynet.be) so eloquently and verbosely pontificated:
> I need to sort a large file starting with the 15 th position.
> What do I use ?

this is a bit vague in two ways: first, your question is kind of ambiguous in
that 'position' may mean line, or byte, second, how far have you gotten?  do you
know about the 'sort' function?  or the 'read' function?  or the 'substr'
function?

be a little more specific yet verbose, and many people will be willing to come
to your aid! :)

hope that helps.

--
               "Give me ambiguity or give me something else."
 ______                       ______ _               _               
(_) |                        (_) |  | |             | |              
    | _   ,_    ,_              _|_ | |  _ _|_  __  | |     _   ,_   
  _ ||/  /  |  /  |  |   |     / | ||/  |/  |  /    |/ \   |/  /  |  
 (_/ |__/   |_/   |_/ \_/|/   (_/   |__/|__/|_/\___/|   |_/|__/   |_/
*+*+*+*+*+*+*+*+*+*+*+* /| *+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+* 
                        \|    tfletche@pcocd2.intel.com
*+*+*+*+*+*+*+*+*+*+*+*+*+*   www-fes.fm.intel.com/~tfletche   *+*+*+*+*+*+*



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

Date: 7 Jan 1998 17:37:50 GMT
From: gbacon@adtran.com (Greg Bacon)
To: smellymama@aol.com (Smellymama)
Subject: Re: TEST IF A VALUE EXISTS IN AN ARRAY
Message-Id: <690ehe$c7s$2@info.uah.edu>

[Posted and mailed]

In article <19980107151201.KAA13309@ladder02.news.aol.com>,
	smellymama@aol.com (Smellymama) writes:
: Need to to test user input to determine if it exists in a prdefined array

This is a FAQ.  Find your answer in the Perl FAQ list at

    http://www.perl.com/CPAN/doc/FAQs/FAQ/PerlFAQ.html

or in the perlfaq manpage.

Hope this helps,
Greg
-- 
open(G,"|gzip -dc");$_=<<EOF;s/[0-9a-f]+/print G pack("h*",$&)/eg
f1b88000b620f22320303fa2d2e21584ccbcf29c84d2258084
d2ac158c84c4ece4d22d1000118a8d5491000000
EOF


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

Date: 7 Jan 1998 17:23:25 GMT
From: gbacon@adtran.com (Greg Bacon)
To: tchrist@perl.com (Tom Christiansen)
Subject: Re: Testing for valid RegExps?
Message-Id: <690dmd$c7s$1@info.uah.edu>

[Posted and mailed]

In article <68ubn9$auo$1@csnews.cs.colorado.edu>,
	Tom Christiansen <tchrist@mox.perl.com> writes:
: How this interacts with a current //g may not be perfect.  Perhaps
: this would be safer.
: 
:     sub is_valid_regex {
: 	my $pat = shift;
: 	my $str = '';
: 	return eval { $str =~ /$pat/, 1 };
:     }	

Or just

    sub is_valid_regex {
        my $pat = shift;

        eval { local $_ = ''; /$pat/, 1 };
    }

TMTOWTDI,
Greg
-- 
open(G,"|gzip -dc");$_=<<EOF;s/[0-9a-f]+/print G pack("h*",$&)/eg
f1b88000b620f22320303fa2d2e21584ccbcf29c84d2258084
d2ac158c84c4ece4d22d1000118a8d5491000000
EOF


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

Date: Wed, 07 Jan 1998 17:38:03 +0100
From: "Peter J. Acklam" <jacklam@ulrik.uio.no>
Subject: Re: Trimming blanks
Message-Id: <34B3AF6A.446B@ulrik.uio.no>

canugi Yorugua wrote:
> 
> I used to "trim" strings (get rid of surrounding blanks) by using
> 
> $str =~ s/^\s*(.*?)\s*$/$1/;   # Get rid of surrounding blanks
> 
> in our Sequent box.
> Now we have ported to a HP box and the @#!?&#&!! is not
> working properly anymore. It trims *only* blanks preceding
> the string but not those after the after.

It should work. There is at least nothing wrong with the regex.
But you should replace it by

$str =~ s/^\s+//;    # Remove leading whitespace.
$str =~ s/\s+$//;    # Remove trailing whitepace.

It it both faster and easier to understand.

Peter


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

Date: 7 Jan 1998 17:56:42 GMT
From: mjtg@cus.cam.ac.uk (M.J.T. Guy)
Subject: Re: unlink return value
Message-Id: <690fkq$k02$1@lyra.csx.cam.ac.uk>

Keith Willis <keith_willis.junk@non-hp-unitedkingdom-om1.om.hp.com> wrote:
>On Wed, 07 Jan 1998 08:05:54 -0600, Dave Barnett
>
>>1.  What is the return value of unlink on success?  On Failure?
>
>Had you simply done 'man unlink' you would realize the answer.
>
> RETURN VALUE
>      unlink() returns the following values:
>
>            0   Successful completion.
>           -1   Failure.  errno is set to indicate the error.
>
>For Grud's sake, doesn't anyone read a man page these days?

That's completely wrong.   You should at least read an _appropriate_
man page.   From perldoc -f unlink:

---------------------------
=item unlink LIST

=item unlink

Deletes a list of files.  Returns the number of files successfully
deleted.
--------------------------

So for the case of a single argument, you get 1 for success and 0 for fail.


Mike Guy


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

Date: Wed, 07 Jan 1998 16:47:57 GMT
From: paul@f1world.com (Paul Ryder)
Subject: Wildcard in  if ( x = a ) ?
Message-Id: <34b3b12b.1318716884@news.u-net.com>

Hi,

Im looking for a way of searching a number of strings and if the
string matches the search varible, it says so.. but how can i make it
react even if say one letter of the word is present (wildcard *) ?

heres the code in question :

if ($FORM{'QUERY'} =~ /$fields[0]/i)

But this only picks up if the full word is present,  

any ideas?

can you mail me at paul@pry.u-net.com if you can help.

Thanks in advance.


_________________________________________________
Paul Ryder                 http://www.f1world.com         
paul@pry.u-net.com         ICQ : 262573
paul@f1world.com
paul@quake2.com


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

Date: 7 Jan 1998 18:34:58 GMT
From: Bob Shair (courtesy) <rmshair@delphi.beckman.uiuc.edu>
Subject: Re: Would yo explain the Perl "pack" command to me?
Message-Id: <690hsi$1pv$1@vixen.cso.uiuc.edu>

David <dperdue@vec.net> wrote:
> Hi, 

> The subject line says it all. I don't know exactly what the pack command
> does.

It builds "records".  This is an old data-processing concept.
A record is a defined assembly of (usually) fixed-length "fields".
Each field holds the contents of a single variable.

The typical use of records is to store data (for transmission or archiving)
on a medium of limited length (punched card, disk sector, etc.).

There's a good explanation of this in the first edition of Programming
Perl (the Camel book), where Job is limited to 8-byte messages by the
limitations of CTBCPP (Clay Tablet Byy Carrier Pigeon Protocol).

This entire chapter, Practical Programming, has helpfully been removed
from the second edition, so that those of you who have started in Perl
later won't compete as strongly with the Perl Pioneers.

$newrec = pack("A2 A6", $beastie, $recnum);
The first argument to pack is a template which defines the structure
of the record to be created.  There should (normally) be a one-to-one
correspondence between the entries in this template and the elements
to be packed, which follow the template.  

Hope this provides enough to read the man page.
-- 

Bob Shair                          rmshair@delphi.beckman.uiuc.edu
Open Systems Specialist    	   Champaign, Illinois		   
/* Not employed by or representing the University of Illinois */


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

Date: 7 Jan 1998 18:39:59 GMT
From: avm@best.com (Anthony Mulligan)
Subject: Re: Would yo explain the Perl "pack" command to me?
Message-Id: <avm-0801981039090001@avm.vip.best.com>

learn to read the frigging man pages.
from the command line type the following

perldoc -f pack

and the following will be displayed

=item pack TEMPLATE,LIST

Takes an array or list of values and packs it into a binary structure,
returning the string containing the structure.  The TEMPLATE is a
sequence of characters that give the order and type of values, as
follows:

    A   An ascii string, will be space padded.
    a   An ascii string, will be null padded.
    b   A bit string (ascending bit order, like vec()).
    B   A bit string (descending bit order).
    h   A hex string (low nybble first).
    H   A hex string (high nybble first).

    c   A signed char value.
    C   An unsigned char value.

    s   A signed short value.
    S   An unsigned short value.
          (This 'short' is _exactly_ 16 bits, which may differ from
           what a local C compiler calls 'short'.)

    i   A signed integer value.
    I   An unsigned integer value.
          (This 'integer' is _at_least_ 32 bits wide.  Its exact size
           depends on what a local C compiler calls 'int', and may
           even be larger than the 'long' described in the next item.)

    l   A signed long value.
    L   An unsigned long value.
          (This 'long' is _exactly_ 32 bits, which may differ from
           what a local C compiler calls 'long'.)

    n   A short in "network" (big-endian) order.
    N   A long in "network" (big-endian) order.
    v   A short in "VAX" (little-endian) order.
    V   A long in "VAX" (little-endian) order.
          (These 'shorts' and 'longs' are _exactly_ 16 bits and
           _exactly_ 32 bits, respectively.)

    f   A single-precision float in the native format.
    d   A double-precision float in the native format.

    p   A pointer to a null-terminated string.
    P   A pointer to a structure (fixed-length string).

    u   A uuencoded string.

    w   A BER compressed integer.  Its bytes represent an unsigned
        integer in base 128, most significant digit first, with as few
        digits as possible.  Bit eight (the high bit) is set on each
        byte except the last.

    x   A null byte.
    X   Back up a byte.
    @   Null fill to absolute position.

Each letter may optionally be followed by a number which gives a repeat
count.  With all types except "a", "A", "b", "B", "h", "H", and "P" the
pack function will gobble up that many values from the LIST.  A * for the
repeat count means to use however many items are left.  The "a" and "A"
types gobble just one value, but pack it as a string of length count,
padding with nulls or spaces as necessary.  (When unpacking, "A" strips
trailing spaces and nulls, but "a" does not.)  Likewise, the "b" and "B"
fields pack a string that many bits long.  The "h" and "H" fields pack a
string that many nybbles long.  The "P" packs a pointer to a structure of
the size indicated by the length.  Real numbers (floats and doubles) are
in the native machine format only; due to the multiplicity of floating
formats around, and the lack of a standard "network" representation, no
facility for interchange has been made.  This means that packed floating
point data written on one machine may not be readable on another - even if
both use IEEE floating point arithmetic (as the endian-ness of the memory
representation is not part of the IEEE spec).  Note that Perl uses doubles
internally for all numeric calculation, and converting from double into
float and thence back to double again will lose precision (i.e.,
C<unpack("f", pack("f", $foo)>) will not in general equal $foo).

Examples:

    $foo = pack("cccc",65,66,67,68);
    # foo eq "ABCD"
    $foo = pack("c4",65,66,67,68);
    # same thing

    $foo = pack("ccxxcc",65,66,67,68);
    # foo eq "AB\0\0CD"

    $foo = pack("s2",1,2);
    # "\1\0\2\0" on little-endian
    # "\0\1\0\2" on big-endian

    $foo = pack("a4","abcd","x","y","z");
    # "abcd"

    $foo = pack("aaaa","abcd","x","y","z");
    # "axyz"

    $foo = pack("a14","abcdefg");
    # "abcdefg\0\0\0\0\0\0\0"

    $foo = pack("i9pl", gmtime);
    # a real struct tm (on my system anyway)

    sub bintodec {
        unpack("N", pack("B32", substr("0" x 32 . shift, -32)));
    }

The same template may generally also be used in the unpack function.

Now why couldn't you have done that yourself?


In article <34B2C79B.5ABFB4D2@vec.net>, David <dperdue@vec.net> wrote:

#Hi, 
#
#The subject line says it all. I don't no exactly what the pack command
#does.
#I don't konw when it might be used. I don't understand what the
#templates are telling the program.
#I read the man page, but still I don't get it. I an reading the llama
#book and have gone thru it a number of times. This seems to be the only
#area that I can't grasp.  I appreciate any insight that you can provide.
#Thanks.
#
#--dp


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

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 1595
**************************************

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