[6389] in Perl-Users-Digest

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

Perl-Users Digest, Issue: 14 Volume: 8

daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Tue Feb 25 21:17:21 1997

Date: Tue, 25 Feb 97 18:00:21 -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           Tue, 25 Feb 1997     Volume: 8 Number: 14

Today's topics:
     Re: Calling html page from perl script????? (Daniel DuBois)
     Re: Calling subroutines <rootbeer@teleport.com>
     Re: Can you create file on the fly with perl? <rootbeer@teleport.com>
     Re: CRC or checksum <sadd@msc.cornell.edu>
     Re: el porvenir di perl und java-script plussier@isd.3com.com
     Re: el porvenir di perl und java-script (Nathan V. Patwardhan)
     Re: File access time (Jason Bodnar)
     File caching problem with NT  and -e <tim@paneris.co.uk>
     Re: Formatting numbers <jander@ml.com>
     Re: Formatting numbers <rootbeer@teleport.com>
     Handling signals without dieing <mccrory@fnal.gov>
     Re: help on error message (Tad McClellan)
     How thread safe is Perl? <marks@telebusiness.co.nz>
     Re: How would I write this more concisely <rootbeer@teleport.com>
     Re: How would I write this more concisely (Tad McClellan)
     Re: need help (Tad McClellan)
     Oracle DB Access from PERL 5!! <mshannon@lds.com>
     Question about the SYSTEM function (Efigenio Ataide)
     Question on "eval" (David Salisbury)
     Re: Question on "eval" <sadd@msc.cornell.edu>
     Re: Regular Expression question <riekhof@primenet.com>
     Re: replaceing stuff (Tad McClellan)
     Re: Using a variable for mode in chmod and mkdir (Tad McClellan)
     Re: Using a variable for mode in chmod and mkdir <jerrym@ibmoto.com>
     Re: weird split prob <billc@tibinc.com>
     Re: Why do I get a ^\ when doing "multi-dimension" key  (Tad McClellan)
     Re: Writing a subroutine (Tad McClellan)
     Digest Administrivia (Last modified: 8 Jan 97) (Perl-Users-Digest Admin)

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

Date: Wed, 26 Feb 1997 01:00:39 GMT
From: dan@spyglass.com (Daniel DuBois)
Subject: Re: Calling html page from perl script?????
Message-Id: <33358846.114918063@news.enteract.com>

On 13 Feb 1997 09:01:56 -0500, nelson <nmljn@wombat.staff.ichange.com>
wrote:

>The reason that is not working is because you are not terminating it
>with two newlines.  Say this instead:
>
>print STDOUT "Location: http://www.axial.co.uk/netx_webx_dnld.html\n\n";

It's not pragmatically necessary, but to be anal, I believe that should be
print STDOUT "Location: http://www.axial.co.uk/n...html\r\n\r\n";

The widely-ignored HTTP specifications indicate that only a CRLF is the
acceptable header delimiter.  A good web server would intercept the output
of a script that did the above and translate the lines into CRLFCRLF from
CRCR, but I highly suspect most web servers aren't that good.

And since just about everyone ignores the CRLF requirement, pretty much all
browsers and clients have robust parsers that will handle lone CRs, and
maybe even lone LFs for some uncompliant Mac servers, so again, it's not
pragmatically necessary.  (It's just the one thing I have knowledge of that
I can point out how smart I am and go neener neener every once in a while.
Yeah, it's pretty pathetic of me.)

-----
Daniel DuBois, Traveling Coderman        www.spyglass.com/~ddubois
   o  The Heroes of Might and Magic II Bible is here!
      http://www.spyglass.com/~ddubois/HOMM2.html
   o  Please note my return address may be invalid in order to
      foil mailing list generation software.


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

Date: Tue, 25 Feb 1997 16:13:33 -0800
From: Tom Phoenix <rootbeer@teleport.com>
To: Luis Torres <ltorres@campus.ruv.itesm.mx>
Subject: Re: Calling subroutines
Message-Id: <Pine.GSO.3.95q.970225160443.13796D-100000@kelly.teleport.com>

On Tue, 25 Feb 1997, Luis Torres wrote:

> Hello, I have a script that uses a module (calling it with use) and has
> one subroutine inside it (the usual readparse sub)... how come when I
> call the sub I get an error saying: 
> 
> Undefined subroutine &main::parse_form_data called at multiplearchivo.pl

The word 'main' in there is the package name that Perl thinks you mean.
When you don't specify another one, Perl tries 'main'. Did you mean to
export the name from the module to your code, or to import it? 

Or, perhaps you want to call it in its own package. Just put the package
name in, something like this.

    &other_package::parse_form_data($parameters);

See the perlmod(1) manpage for more information. Hope this helps!

-- Tom Phoenix        http://www.teleport.com/~rootbeer/
rootbeer@teleport.com   PGP  Skribu al mi per Esperanto!
Randal Schwartz Case:     http://www.lightlink.com/fors/



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

Date: Tue, 25 Feb 1997 16:20:41 -0800
From: Tom Phoenix <rootbeer@teleport.com>
To: Dico Reyers <dico@isn.net>
Subject: Re: Can you create file on the fly with perl?
Message-Id: <Pine.GSO.3.95q.970225161551.13796F-100000@kelly.teleport.com>

On Tue, 25 Feb 1997, Dico Reyers wrote:

> I would like to know if you can create a file on the fly with PERL.

Yes, you can.

> Say if $filename = johnny;  

I think you'll usually want quote marks around the string there. Perl's -w
option will remind you if you've left them off.

> I would like the PERL script to make an empty file called johnny. 

What should it do if the file already exists? Should it wipe it out, or
should it assume that everything is fine, and go on? Or should it stop in
its tracks because now something has gone wrong? Do you want the file to
be open for output so that your script can put more data in it?

This will do some of that. :-)  Hope this helps!

    open FILE, "> $filename"
	or die "Can't create '$filename': $!";
    close FILE;

-- Tom Phoenix        http://www.teleport.com/~rootbeer/
rootbeer@teleport.com   PGP  Skribu al mi per Esperanto!
Randal Schwartz Case:     http://www.lightlink.com/fors/



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

Date: Tue, 25 Feb 1997 20:03:06 -0500
From: Michael Sadd <sadd@msc.cornell.edu>
To: Brian Flanagan <flanagan@twisto.compaq.comm>
Subject: Re: CRC or checksum
Message-Id: <33138BCA.ABDFB23@msc.cornell.edu>

I have had similar questions.  

I know that I can generate checksums with unpack alone.
For example, to checksum the stanard input,

	@a=<>;
	$sum=unpack("%16C*","@a");

assuming $"="".  This of course has the disadvantage of
slurping the whole file into memory first.  'Programming
perl' suggests:

     while (<>) {
        $checksum += unpack("%16C*", $_);
     }
     $checksum %= 65536;

The two methods do not give the same results, nor do they
agree with the system V sum, contrary to the claims in the book.

	Mike	

Brian Flanagan wrote:
> 
> Hi,
> 
> I would like to generate a semi-unique number for a
> large array of strings and integers, using a CRC or
> checksum algorithm.  I think I will need to use pack,
> but don't know how to do any byte operations on its
> return value.  Any suggestions would be helpful.
> 
> --
> Brian


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

Date: 25 Feb 1997 18:25:00 -0500
From: plussier@isd.3com.com
Subject: Re: el porvenir di perl und java-script
Message-Id: <ynilo8co4dv.fsf@guthrie.i-have-a-misconfigured-system-so-shoot-me>

Tom Christiansen <tchrist@mox.perl.com> writes:

> Remind me to post my chthonic camel sentence sometime.

Tom,

Would you please post your chthonic camel sentence sometime ?

;)

Seeya,
Paul
=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
- Paul Lussier		=   It is a good day	=The next best thing to doing -
= 3Com ISD Division	-    to put slinkies	-something smart is not doing =
- plussier@isd.3com.com	=     on escalators	=      something stupid.      -
=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
     =Rich Cook: "Programming Today Is A Race Between Software Engineers-
     -Striving To Build Bigger And Better Idiot-Proof Programs, And The =
     = Universe Trying To Produce Bigger And Better Idiots. So Far, The -
     -=			     Universe Is Winning."                     -=
      -=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=


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

Date: 25 Feb 1997 23:35:31 GMT
From: nvp@shore.net (Nathan V. Patwardhan)
Subject: Re: el porvenir di perl und java-script
Message-Id: <5evt03$q53@fridge-nf0.shore.net>

plussier@isd.3com.com wrote:

: Would you please post your chthonic camel sentence sometime ?

I think it's already posted on the www.ora.com website in the description
of _Programming Perl_.

--
Nathan V. Patwardhan
nvp@shore.net
"Lane, I've been in high school for
seven years.  I'm no dummy"
	--Charles Demar from _Better Off Dead_


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

Date: Tue, 25 Feb 1997 23:23:38 GMT
From: jason@cimedia.com (Jason Bodnar)
Subject: Re: File access time
Message-Id: <33137446.18654502@news.onr.com>

jhamlin@ai.uga.edu (Jon Hamlin) wrote:

>How can I get a file's access time (not modification time) in Perl?
>utime allows it to be changed, but I need to read it, not write it.
>

$atime = (stat FILE)[8];


-- 
Jason C. Bodnar
jasonb@onr.com
Internet Programmer
Cox Interactive Media


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

Date: Wed, 26 Feb 1997 00:12:19 +0000
From: Tim Pizey <tim@paneris.co.uk>
Subject: File caching problem with NT  and -e
Message-Id: <33137FE3.7824@paneris.co.uk>

Today I find that the client's dual boot pentium running NT 4.00  and 
Win 3.11 loses files. This _really_ is inconsistent behaviour.
Writing in NT Perl5 (110-i86) I call Folio Views WCREATE, which takes 
two input files and produces an output file and a log file. 

so:

system("C:\\views31\wcreate.exe file.inp file.out -L file.log");
if (-e "file.log")
{
  print "ok\n";   #    
}
else
{
  print "Not there\n";
}

but the file is there and you can see NT Explorer update the directory
window.

I have heard that NT uses file caching extensively, could this be the
cause? 

Tim
tim@paneris.co.uk
Context Computing


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

Date: 25 Feb 1997 16:45:01 -0500
From: Jim Anderson <jander@ml.com>
Subject: Re: Formatting numbers
Message-Id: <wkbiv3gsgpu.fsf@swapsdvlp15.i-did-not-set--mail-host-address--so-shoot-me>

dico@isn.net (Dico Reyers) writes:

> 	
> Hello There...
> 
> I would like some help with formating numbers.
> 
> Say that:
> 
> $number = 1.345;
> 
> I would like that number rounded off to two decimal spots. So number
> would be  1.35  .

RTFM and lookup 'sprintf'


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

Date: Tue, 25 Feb 1997 16:21:55 -0800
From: Tom Phoenix <rootbeer@teleport.com>
To: Dico Reyers <dico@isn.net>
Subject: Re: Formatting numbers
Message-Id: <Pine.GSO.3.95q.970225162116.13796G-100000@kelly.teleport.com>

On Tue, 25 Feb 1997, Dico Reyers wrote:

> I would like some help with formating numbers.

You probably want sprintf, which is documented in perlfunc(1) and your
system's manpages. Hope this helps!

-- Tom Phoenix        http://www.teleport.com/~rootbeer/
rootbeer@teleport.com   PGP  Skribu al mi per Esperanto!
Randal Schwartz Case:     http://www.lightlink.com/fors/



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

Date: Tue, 25 Feb 1997 17:05:08 -0600
From: Elliott McCrory <mccrory@fnal.gov>
Subject: Handling signals without dieing
Message-Id: <33137024.36DA@fnal.gov>

(May have already been posted, not sure).

I want to set an alarm in perl 5.003, do something and then continue on,
until the next alarm comes.  I have this snippet:

#!/usr/local/bin/perl

$sec = 10;
$SIG{ALRM} = 'mysub';

alarm $sec;
print "Waiting\n";
while (<>) {
    print "Line read $_";
    alarm $sec;			# Wait some more
}

sub mysub {
    print "Alarm signal caught\n";
    return;   #This line is irrelevant to behaviour
}

which does this:

solaris $ ./test-alarm.pl
Waiting
Alarm signal caught
solaris $ 

Program dies *immediately* after execution of &mysub.

How do I return from &mysub without killing the program?

-- 
Elliott S. McCrory, Ph. D.	| mccrory@fnal.gov
Fermi National Accelerator Lab	| http://www-linac.fnal.gov/~mccrory
MS 307, PO Box 500		| Phone: 630-840-4808
Batavia, IL  60510		| FAX: 630-840-8590


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

Date: Tue, 25 Feb 1997 15:34:35 -0600
From: tadmc@flash.net (Tad McClellan)
Subject: Re: help on error message
Message-Id: <btlve5.853.ln@localhost>

Keith Warner Colvin (colvin@aloha.net) wrote:
: Aloha from Hawai'i.....

: >Code

:   sub open_error
:     {

: # Assign to the local variable $file_name, the filename that we passed
: # to this subroutine from the referenceing routine.

:     local ($filename) = @_;

: # Let the client know that the script was unable to open the requested file
: # and then die so that the routine does not continue

:     print "I am really sorry, but for some reason I was unable to open
:     <P>$filename<P>  Would you please make sure that the filename is
:     correctly defined in define_variables.pl, actually exists, and has the
:     right permissions relative to the web browser.  Thanks!";
:     die;
:     }


: > I Run my script and I get this:

: Content-type: text/html

: I am really sorry, but for some reason I was unable to open
:     <P>./User_carts<P>  Would you please make sure that the filename is
:     correctly defined in define_variables.pl, actually exists, and has the
:     right permissions relative to the web browser.  Thanks!# Died.
: File ':cgi-lib.sol'; Line 71

: What do I do next?
  ^^^^^^^^^^^^^^^^^

Tell us what you don't like about the above would be a good start!

ie. What's your problem? It is doing what it is supposed (and what
you told it) to do.

If you don't want the indenting, then don't put indenting in your print.

If you don't want the message from die, then:

die "\n";


--
    Tad McClellan                          SGML Consulting
    Tag And Document Consulting            Perl programming
    tadmc@flash.net


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

Date: 26 Feb 1997 01:29:47 GMT
From: "Mark Scaletti" <marks@telebusiness.co.nz>
Subject: How thread safe is Perl?
Message-Id: <01bc2384$b7265850$d5e824ca@marksnt>

Hi,

I'm looking at using Perl as a component of a multithreaded application.  I
have been unable to find any information about how thread safe Perl is. 
Are there any thread-safe versions of Perl?

Mark Scaletti
marks@telebusiness.co.nz


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

Date: Tue, 25 Feb 1997 16:31:46 -0800
From: Tom Phoenix <rootbeer@teleport.com>
To: Gene Johannsen <gej@spamalot.mfg.sgi.com>
Subject: Re: How would I write this more concisely
Message-Id: <Pine.GSO.3.95q.970225162538.13796H-100000@kelly.teleport.com>

On 25 Feb 1997, Gene Johannsen wrote:

> What would be a more concise way of writing this?  

> if ($#ARGV == -1) {
>     $sked_file = "sked";
> }
> else {
>     $sked_file = shift;
> }
> 
> if ($#ARGV == -1) {
>     $min = 5;
> }
> else {
>     $min = shift;
> }

I've seen people use things like this.

    # Read in args, or use defaults
    $sked_file = 	shift || 'sked';
    $min = 		shift || 5;

The disadvantage here is that neither argument can be logically false, but
that's usually not a problem. If it might be, this might be better.

    ($sked_file, $min) = ('sked', 5);    # Set defaults
    $sked_file = shift if @ARGV;
    $min =       shift if @ARGV;

Hope this helps!

-- Tom Phoenix        http://www.teleport.com/~rootbeer/
rootbeer@teleport.com   PGP  Skribu al mi per Esperanto!
Randal Schwartz Case:     http://www.lightlink.com/fors/



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

Date: Tue, 25 Feb 1997 18:31:31 -0600
From: tadmc@flash.net (Tad McClellan)
Subject: Re: How would I write this more concisely
Message-Id: <3900f5.7h4.ln@localhost>

Gene Johannsen (gej@spamalot.mfg.sgi.com) wrote:
: What would be a more concise way of writing this?  I'm not looking for
: anything obfuscated, just something a little shorter and a little
: clearer:


: if ($#ARGV == -1) {
:     $sked_file = "sked";
: }
: else {
:     $sked_file = shift;
: }

: if ($#ARGV == -1) {
:     $min = 5;
: }
: else {
:     $min = shift;
: }

: It just parses two command line arguments, a filename and a time, both
: of which are optional.


$sked_file = shift or $sked_file = "sked";

$min = shift or $min = 5;


--
    Tad McClellan                          SGML Consulting
    Tag And Document Consulting            Perl programming
    tadmc@flash.net


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

Date: Tue, 25 Feb 1997 18:40:08 -0600
From: tadmc@flash.net (Tad McClellan)
Subject: Re: need help
Message-Id: <8p00f5.ii4.ln@localhost>


yncera@ids2.idsonline.com wrote:

: Subject: Re: need help
               ^^^^^^^^^

need subject


: If I put  $Imput=<> it will wait there until I hit any keys follow by
: the enter key. How can I get only just one key without having to use
: the enter key. I am using Perl 5.
                 ^^^^^^^^^^^^^^^^^

>From the fine Perl FAQ (as I'm sure you are a good 'net citizen, and
therefore spent two-three minutes trying to find the answer in 
available free documentation before posting to thousands of computers
around the entire World) I guess that you missed this one:


4.31) How can I read a single character from the keyboard under UNIX and DOS?


(I guess you also missed the article posted here regularly about how
 to choose good Subject: headers that will minimize the chance of 
 people ignoring you and not reading your articles...)


--
    Tad McClellan                          SGML Consulting
    Tag And Document Consulting            Perl programming
    tadmc@flash.net


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

Date: Tue, 25 Feb 1997 18:22:06 -0500
From: Michael Shannon <mshannon@lds.com>
Subject: Oracle DB Access from PERL 5!!
Message-Id: <3313741E.799B@lds.com>

Hi,

I was wondering if anyone knew anything about accessing an Oracle
database stored procedures from Perl. I know there existed an Oraperl
for Perl4.0, but apprently this was not updated for Perl 5.

Thanks for your help...mjs
-- 
Michael J. Shannon, Jr.    
mshannon@lds.com             Logical Design Solutions, Inc.
201-971-0100 ext 161         465 South Street   Suite 103
201-971-0103 (fax)           Morristown,  NJ  07960


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

Date: Wed, 26 Feb 1997 00:07:46 GMT
From: ataide@planetarium.com.br (Efigenio Ataide)
Subject: Question about the SYSTEM function
Message-Id: <33137d89.3808563@newsfeed.pnl.gov>

In a Perl program I am trying to do the following:

system("/sbin/diplogin", $user) == 0 || die "calling diplogin: $?\n";
&mysub;
  .
When the user closes the connection the
program 'diplogin' ends (abnormaly?), and the subroutine 
mysub isn't called.
Is there a way to have this subroutine called after the program
diplogin?

Thanks in advance for any help.
Efigenio Ataide
ataide@planetarium.com.br


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

Date: 26 Feb 1997 00:11:06 GMT
From: salisbur@venus.fsl.noaa.gov (David Salisbury)
Subject: Question on "eval"
Message-Id: <5evv2q$5eh@lace.colorado.edu>


Okay, I admit it, I'm not a perl wiz.  Can someone please tell me
why the code below doesn't work, and maybe even a solution.
I've tried several ways, but I would think that the "\" escape
protects the $ from the first pass of the eval.

-------------------
#!/bin/perl
 
$sortorder='$date$type';
 
$date='05/01/96';
$type="bob";
 
$sometext = "this is some text";
 
eval "\$anArray{$sortorder} = \$sometext";  ##<--- why no work??
 
foreach $i ( keys(%anArray) ) {
   print "$i\n";
}
 
exit;
-- 

If the directory name is any indication, I'm running perl 5.

_____________________________
Value is the predecessor of structure.  -Pirsig



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

Date: Tue, 25 Feb 1997 20:24:15 -0500
From: Michael Sadd <sadd@msc.cornell.edu>
To: David Salisbury <salisbur@venus.fsl.noaa.gov>
Subject: Re: Question on "eval"
Message-Id: <331390BF.6FCCC933@msc.cornell.edu>

Try instead quoting the key:
#!/bin/perl
 
$sortorder='$date$type';
 
$date='05/01/96';
$type="bob";
 
$sometext = "this is some text";
 
eval "\$anArray{\"$sortorder\"} = \$sometext";  ##<--- why no work??
foreach $i ( keys(%anArray) ) {
   print "$i\n";
}
__END__
05/01/96bob

Something which helps me with 'eval' problems when in perl, TCL,
sh, etc. is to print out what I am eval'ing--then I see what
is being passed to the parser.  You would then see that
you are passing it a key like $date$time, which is not a valid perl
espression--you have to either interpolate the variable within
a string, or catenate them, or some such operation.

	Mike


David Salisbury wrote:
> 
> Okay, I admit it, I'm not a perl wiz.  Can someone please tell me
> why the code below doesn't work, and maybe even a solution.
> I've tried several ways, but I would think that the "\" escape
> protects the $ from the first pass of the eval.
> 
> -------------------
> #!/bin/perl
> 
> $sortorder='$date$type';
> 
> $date='05/01/96';
> $type="bob";
> 
> $sometext = "this is some text";
> 
> eval "\$anArray{$sortorder} = \$sometext";  ##<--- why no work??
> 
> foreach $i ( keys(%anArray) ) {
>    print "$i\n";
> }
> 
> exit;
> --
> 
> If the directory name is any indication, I'm running perl 5.
> 
> _____________________________
> Value is the predecessor of structure.  -Pirsig


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

Date: 25 Feb 1997 17:54:04 -0700
From: Darrel Riekhof <riekhof@primenet.com>
To: jfriedl@wg.omron.co.jp
Subject: Re: Regular Expression question
Message-Id: <3313962B.5653@primenet.com>

> With (a*), the contents of the parens is the regex /a*/, so what that
> matches is what $1 will be. This can be "", "a", "aa", "aaa", etc.,
> depending on the string. If your string was "a", then it will be "a".
> 
> |> Then I tried (a*)* and $1 had ''.
> 
> Yup. $1 can be filled by /a*/, and that can match "".

I still don't understand this part.  /a*/ will match
all the a's.  Then the outer star should match 0 or
more of the inner, but it chooses to match the empty
string.  I don't like this behavior.  Is there a reason
for it?

> FWIW, it's covered on page 218 of my book.

I tried to buy that book a couple weeks ago, but the local 
Barnes & Nobles couldn't get a copy.  :(  I'll have to
try again.

> |> IMO, the most logical behavior would be for any
> |> expression inside parens with a global asterisk, (<expr>*), to return
> |> '' in its backref.
> 
> So you're saying that
>         "word" =~ m/(\w*)/
> shouldn't set $1 to "word"???

Yeah, you're right--that would be stupid.

Still trying to figure out the reason why it doesn't always
remember the maximal match......

Darrel
-- 
Darrel Riekhof
riekhof@primenet.com
Visit http://www.connectcorp.com


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

Date: Tue, 25 Feb 1997 15:55:18 -0600
From: tadmc@flash.net (Tad McClellan)
Subject: Re: replaceing stuff
Message-Id: <64nve5.fa3.ln@localhost>

Vetle Roeim (vetler@ifi.uio.no) wrote:

: In article <33131f70.16664575@news>, tjordan@ns15.cca.rockwell.com (Terence Jordan) writes:
: > On 25 Feb 1997 17:14:30 +0100, vetler@ifi.uio.no (Vetle Roeim)
: > scripted:
: > 
: > >ex: a line says; <A HREF="http://www.perl.org">Perl</A>, and i want it to
: > >say "http://www.perl.org".
: > >
: > 
: > ok, let's set up the following situation:
: > 
: > $var1="It's not unusual to be loved by anyone...\n";
: > $var2=substr($var1,9,7);
: > print "$var1\n Ok, maybe it is $var2";
: > 
: > >help, please :)
: > No problem.

: thanks, but it's not quite what i'm looking for.
: you're piece of code requires me to know exactly where the
: string i want is located and how long it is.
: what i do know, is that it starts with http:// and ends with either
: a " or a >.
: ... so it's not exactly what i'm looking for.

: what i've tried so far, is
: this:

:           $line =~ /http.*"/;
:           print $&."\n";

: but it doesn't work exactly the way i want it.

: i want it to stop when it hits a " _or_ a >. how can i do that?
                                               ^^^^^^^^^^^^^^^^^

$line =~ /http[^">]*/;


--
    Tad McClellan                          SGML Consulting
    Tag And Document Consulting            Perl programming
    tadmc@flash.net


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

Date: Tue, 25 Feb 1997 16:28:23 -0600
From: tadmc@flash.net (Tad McClellan)
Subject: Re: Using a variable for mode in chmod and mkdir
Message-Id: <72pve5.0j3.ln@localhost>

Robert A. Goff (ragoff@sandia.gov) wrote:
: I need help using a variable for the mode parameter in chmod and mkdir,
: e.g.

: $dirmode = '0777';
: $filemode = '0755';


$dirmode = 0777;
$filemode = 0755;

Single quotes make it a string with four characters in it, not
the number represented by the octal encoding...


: mkdir("$FORM{'cwd'}/$FORM{'dirname'}", $dirmode);

umask also plays a part it the permissions that you end up with after
mkdir()...


: chmod($filemode, "$FORM{'cwd'}/$FORM{'filename'}");

: which results in a file/directory with the wrong mode.  Using the
: literal octal numbers gets me the right mode, so I obviously don't know
: how to cast a variable to an octal value.  Any help appreciated,
: including telling me which part of TFM to R.


--
    Tad McClellan                          SGML Consulting
    Tag And Document Consulting            Perl programming
    tadmc@flash.net


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

Date: Tue, 25 Feb 1997 15:59:20 -0600
From: Jerry Monsen <jerrym@ibmoto.com>
Subject: Re: Using a variable for mode in chmod and mkdir
Message-Id: <331360B8.2781@ibmoto.com>

Robert A. Goff wrote:
>> $dirmode = '0777';
             ^    ^
> $filemode = '0755';
              ^    ^
> how to cast a variable to an octal value.  Any help appreciated,
> including telling me which part of TFM to R.

Try removing those quotes. They make it a string rather than an octal
number.

Hope that helps.

Jerry


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

Date: Tue, 25 Feb 1997 19:47:56 -0500
From: Bill Cowan <billc@tibinc.com>
To: "Douglas L. Cordero, PhD" <dcordero@giss.nasa.gov>
Subject: Re: weird split prob
Message-Id: <3313883C.7848@tibinc.com>

Douglas L. Cordero, PhD wrote:
> 
> Hi all:
>         This one is making me crazy.  Where am I screwing up?
> 
> > cat test.pl
> 
> #!/usr/local/bin/perl -w
> 
> $line = "/lastly/I/have.hadit/jkdnkjnvf.89090100";
> 
> @fields = split(/./, $line);
                  ^^^
Try /\./ as the pattern for your split on period (I assume.). 

The problem is that the period is a pattern matching character ("match
anything but newline") and needs to be escaped to be used as a literal
character. 


> 
> print "Here is field 0:",$fields[0],":\n";
> print "Here is field 1:",$fields[1],":\n";
> print "Here is field 2:",$fields[2],":\n";
> 
> RESULTS:
> 
> > test.pl
> 
> Use of uninitialized value at junk2.pl line 7.
> Here is field 0::
> Use of uninitialized value at junk2.pl line 8.
> Here is field 1::
> Use of uninitialized value at junk2.pl line 9.
> Here is field 2::
> 
> Any help?
> 
> 
> ********************************************************
> Doug Cordero
> Science Systems and Applications, Inc.
> NASA - Goddard Institute for Space Studies
> email:   dcordero@giss.nasa.gov
> ********************************************************

-- Bill
-----------------------------------------------------------------------
Bill Cowan <billc@tibinc.com>    Voice:919-490-0034   Fax:919-490-0143
Tiburon, Inc./3333 Durham-Chapel Hill Blvd Suite E-100/Durham, NC 27707


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

Date: Tue, 25 Feb 1997 15:42:24 -0600
From: tadmc@flash.net (Tad McClellan)
Subject: Re: Why do I get a ^\ when doing "multi-dimension" key in associative array ?
Message-Id: <0cmve5.l73.ln@localhost>

Wai Fai Yee~ (wyee@sedona.intel.com) wrote:


: Hi everyone,

:      	I checked the Perl5 book and the items listed under "Arrays and Shell 
: and External Programs Interaction" and "General Programming, Regexps and I/O" in
: the FAQ but did not find answers to my question - so I am going to ask it.

: 	Following is the program and its output which got me confused. I have
: a nested loop and store a value in an associative array using

:        $buf{$var1,$var2}++;  where $var1 and $var2 are ordinary variables.
                               ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

So, that would make '$var1,$var2' a LIST, right?

Why don't you just concatenate them instead: '$var1.$var2'?
                                                   ^
                                                   ^


: However when I tried to retrieve the value of the associative array using
: "$var1"."$var2" as the key, I got a NULL (See output from program). I then 
  ^^^^^^^^^^^^^^^

That's not the same key that you set earlier...


: redirected the output to a file and when I do a "cat" and "more" on the file, 
: I got this, 


--
    Tad McClellan                          SGML Consulting
    Tag And Document Consulting            Perl programming
    tadmc@flash.net


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

Date: Tue, 25 Feb 1997 15:52:24 -0600
From: tadmc@flash.net (Tad McClellan)
Subject: Re: Writing a subroutine
Message-Id: <oumve5.1a3.ln@localhost>


[ please limit your line lengths to 70-72 characters as is 
  Usenet custom... ]


Angel Leyva (airborne@cybernex.net) wrote:
: I want to write a subroutine that accepts a text string and returns it in a new
: form.

: Basically, I want to strip some characters and replace others. For example, I
: want to strip leading and trailing spaces and newlines.

: I am sure that there are several ways to do this, but the two ways that I am
: interested in are first, have the string that I pass in get the new values
: automatically, like as a global variable. The second way would be assign it back
: to itself as I call the routine, then have the routine return the result. I want
: the result to replace what was passed in. Please provide examples on how to call
: the routines, as well as the snip of code for the routine.

: EXAMPLE:

: $variable1 = &StripExtraChars($variable1);
: # note the same variable name

-------------
#! /usr/bin/perl -w

$variable1="   Angel Leyva    \n\n";
print "before: '$variable1'\n";

$variable1 = &StripExtraChars($variable1);
print "after: '$variable1'\n";


sub StripExtraChars {
   my $str = $_[0];
   $str =~ s/^\s+|\s+$//g;
   return $str;
}
-------------


: The other way being simply

The other way is a Bad Thing. Don't use subroutines that affect
global variables.

I don't want to contribute to the abuse of good programming, so I'll
just let you figure out how to do this yourself (unless you take my
advice, then you won't _want_ to do this ;-)



: &StripExtraChars($some_global_variable);
: #$some_global_variable now has the new string and no trace of the old one.

: All help and suggestions appreciated.

Hope that helped!


--
    Tad McClellan                          SGML Consulting
    Tag And Document Consulting            Perl programming
    tadmc@flash.net


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

Date: 8 Jan 97 21:33:47 GMT (Last modified)
From: Perl-Request@ruby.oce.orst.edu (Perl-Users-Digest Admin) 
Subject: Digest Administrivia (Last modified: 8 Jan 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.

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

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