[7127] in Perl-Users-Digest

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

Perl-Users Digest, Issue: 752 Volume: 8

daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Mon Jul 21 04:17:14 1997

Date: Mon, 21 Jul 97 01:01:48 -0700
From: Perl-Users Digest <Perl-Users-Request@ruby.OCE.ORST.EDU>
To: Perl-Users@ruby.OCE.ORST.EDU (Perl-Users Digest)

Perl-Users Digest           Mon, 21 Jul 1997     Volume: 8 Number: 752

Today's topics:
     Quick Substitute Tip Req'd <pdenman@ims.ltd.uk>
     Re: Quick Substitute Tip Req'd (Tad McClellan)
     Seeing if a pipe worked <philip@cd.co.uk>
     Re: Sorting Multiple Arrays <sfairey@adc.metrica.co.uk>
     Re: Sorting Multiple Arrays (Daniel G. Drumm)
     Re: Subsecond time in perl (a la gettimeofday(2)) (Clay Irving)
     Re: Using STDIN for an IF/ELSE script <sfairey@adc.metrica.co.uk>
     Re: Using varaibles from a template file (dave)
     Re: What is--->>  19.483u 0.216s 0:12.71 154.9% 0+0k 0+ <jheck@merck.com>
     Re: Where can I find Perl? <sfairey@adc.metrica.co.uk>
     Re: Where can I find Perl? (Chris Schleicher)
     Re: Why: @{$_[0]} for arg in subroutine <sfairey@adc.metrica.co.uk>
     Re: Why: @{$_[0]} for arg in subroutine <mark@tstonramp.com>
     Digest Administrivia (Last modified: 8 Mar 97) (Perl-Users-Digest Admin)

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

Date: Thu, 17 Jul 1997 16:32:17 +0100
From: Paul Denman <pdenman@ims.ltd.uk>
Subject: Quick Substitute Tip Req'd
Message-Id: <33CE3B01.FD9@ims.ltd.uk>

Hello,

It's the end of the day, and my brain is dying!
Has anyone got a quick substitute routine which will only
keep any alpha-numeric characters, including spaces?

My attempts so far

(Including: $value =~ s/\D.*//;    $value =~ s/\W//; + more!!)

 have resulted in either alpha-numeric without the spaces, 
alpha & spaces, or numeric & spaces but not the combined effect I
require.

I would be very grateful!

Thanks,

Paul.


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

Date: Thu, 17 Jul 1997 22:52:22 -0500
From: tadmc@flash.net (Tad McClellan)
Subject: Re: Quick Substitute Tip Req'd
Message-Id: <m9pmq5.pp6.ln@localhost>

Paul Denman (pdenman@ims.ltd.uk) wrote:
: Hello,

: It's the end of the day, and my brain is dying!
: Has anyone got a quick substitute routine which will only
: keep any alpha-numeric characters, including spaces?
           ^^^^^^^^^^^^^^^^^^^^^^^^

I'll assume these are the same as \w


: My attempts so far

: (Including: $value =~ s/\D.*//;    $value =~ s/\W//; + more!!)

:  have resulted in either alpha-numeric without the spaces, 
: alpha & spaces, or numeric & spaces but not the combined effect I
: require.

: I would be very grateful!


s/[^\w ]//g;          # anything except word char or space char

OR

s/[^\w\s]//g;         # anything except word char or white space char
                      # (includes tab and newline)

OR

s/[^a-zA-Z0-9 ]//g;   # anything except lower case letters, upper case
                      # letters, digits, or space

OR (the best way)

tr/a-zA-Z0-9 //cd;    # see the perlop man page for tr///



: Thanks,

You're welcome.


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


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

Date: Thu, 17 Jul 1997 16:05:00 +0100
From: Philip M Jones <philip@cd.co.uk>
Subject: Seeing if a pipe worked
Message-Id: <33CE349C.41C6@cd.co.uk>

Hi,

I am doing a pipe in perl which looks like this:

$prostar="pro-xm -batch";
open(PROSTAR,"|$prostar")

Now I would like to see if the pipe has worked so I thought that

open(PROSTAR,"|$prostar") or die "Cannot find prostar";

may work.  I get a fail:

Can't exec "pro-xm": No such file or directory at sincurvemesh.pl line
89

but I get no die.  What do I need to do?

Thanks in advance

Philip M Jones


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

Date: Thu, 17 Jul 1997 09:33:03 +0100
From: Simon Fairey <sfairey@adc.metrica.co.uk>
To: "Daniel G. Drumm" <dgd@nebula.is.rpslmc.edu>
Subject: Re: Sorting Multiple Arrays
Message-Id: <33CDD8BF.2781@adc.metrica.co.uk>

Daniel G. Drumm wrote:
> 
> I've looked through Turqoise Camel and TC's Perl.com pages on Data
> Structures, but I'm unclear on the best way to sort multiple arrays.
> 
> I have 6 arrays: @name, @time, @color, @foo, @bar, @id
> 
> Now, since I did a split() and push() in a while loop, $name[5]
> corresponds to the guys's id in $id[5], etc.
> 
> I want to sort by ONE array, say @id, and not get out of sync with the
> other arrays.
> 
> --
> --
> Daniel G. Drumm - ddrumm@rush.edu
> Rush Presbyterian St. Luke's Medical Center - Chicago, IL
> Network Division - Information Services

I would be tempted to introduce a further array, say @index, then when
you sort @id make the same swaps in @index. In this way you might start
with (1,2,3,4,5) in @index but after sorting @id @index might look like
(3,4,2,1,5) then as you access elements in @id you can lookup in @index
to see what the corresponding position is in the other related arrays (
the bonus with this is that you don't need to sort every single array ).
I hope this is sufficient info to get you started.

Simon


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

Date: 17 Jul 1997 20:06:04 GMT
From: dgd@nebula.is.rpslmc.edu (Daniel G. Drumm)
Subject: Re: Sorting Multiple Arrays
Message-Id: <5qltvc$llj@nebula.is.rpslmc.edu>

M.J.T. Guy (mjtg@cus.cam.ac.uk) wrote:
: The trick is to make an array of indices and sort that.   Then permute
: each array according to the reordered indices:
:     my @index = sort {$id[$a] cmp $id[$b] } 0..$#id;
:     @id = @id[@index];
:     @name = @name[@index];
:     @time = @time[@index];
:       ... etc
: Mike Guy

Thanks to Jon Orwant, Mike Guy and the rest who answered.

On Thu, 17 Jul 1997, Jon Orwant wrote:

> # Our three parallel arrays, which we'll sort by time
> @name  = qw(cowboy wonderland wild! chorus circus innocents);
> @time  = qw(1986 1982 1991 1987 1994 1990);
> @color = qw(white black blue green yellow fuchsia);
> 
> # Our index array, containing the integers 0 through 5
> @index = (0..$#time);
> 
> @index = sort { length($time[$a]) <=> length($time[$b]) } @index;
> 
> @name  = @name[@index];
> @time  = @time[@index];
> @color = @color[@index];
> 
> print "@name\n@time\n@color";
  
Jon,
  
Indeed, this is the solution I was looking for. I examined using 
references, but thought there had to be a way like this to solve it. Thank
you very much. BTW, I enjoy the Perl Journal quite a bit.
  
One last question, the Camel Book says one will be sorry if one attempts  
to toy with $a and $b in the sort function. If $name[6] eq "Daniel Drumm",
what is the best method for sorting by last name? Would one do:

@index = (0..$#name);

for ($i = 0; $i < $#name; ++$i) {
    $lastname[$i] = split(' ',$name[$i]);
}
 
@index = sort { length($lastname[$a]) <=> length($lastname[$b]) } @index;

Or is there a way to avoid this extra loop?

--
--
Daniel G. Drumm - ddrumm@rush.edu
Rush Presbyterian St. Luke's Medical Center - Chicago, IL
Network Division - Information Services


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

Date: 17 Jul 1997 09:19:52 -0400
From: clay@panix.com (Clay Irving)
Subject: Re: Subsecond time in perl (a la gettimeofday(2))
Message-Id: <5ql65o$ctm@panix.com>

In <33CC41DF.3883@NYC.Thinkbank.COM> Chuck Ocheret <chuck@NYC.Thinkbank.COM> writes:

>Perhaps I'm just blind but I can't seem to find the equivalent of
>gettimeofday() in Perl.  Is it really there or is there some other
>interface to get subsecond time in Perl.

Modules are your friend.

It's in Time::HighRes available on CPAN.

-- 
Clay Irving                                        See the happy moron,
clay@panix.com                                     He doesn't give a damn,
http://www.panix.com/~clay                         I wish I were a moron,
                                                   My God! Perhaps I am!


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

Date: Thu, 17 Jul 1997 14:03:24 +0100
From: Simon Fairey <sfairey@adc.metrica.co.uk>
To: Brad Nelson <norseman@erols.com>
Subject: Re: Using STDIN for an IF/ELSE script
Message-Id: <33CE181C.15FB@adc.metrica.co.uk>

Brad Nelson wrote:
> 
> Hello,
> 
> I'm trying to have a perl script call one of two other scripts based on a
> STDIN to a question.  The STDIN has to equal a regular expression as below.
> (This is on a HPUX 10.x unix system).
> 
> REGEXP format is (ALPHA)(ALPHA)-##-#### or (ALPHA)#-##-####, using # for
> numbers.  Example: AA-00-1111 or A0-00-1111.
> 
>     I can't figure out how to have perl "cd" to a lower directory, pass the
> STDIN/variable to
>  a ksh/sed/awk script and run it.
> 
>     I have the ksh/sed/awk script returning a result file and that's where
> I want the process to end.
> 
>     Specifically:
> 
> #!/users/bin/perl
> print "What data do you want to search the file on?  \n"
> chop($data=<STDIN>);
> 
> # MY PSEUDOPERL BELOW:

We don't want PSEUDOPERL here, real live specimens only :)

> if ($data eq /[A-Za-z][A-Za-z]\-[0-9]\{2\}\-[0-9]\{4\}/ || $data eq
> /[A-Za-z][0-9]\-[0-9]\{2\}\-[0-9]\{4\}/)

Read the perlop man page its all there.

For a start you want to be using '=~' not 'eq', you don't need to escape
'-' and you also don't need to escape the curly braces if you are using
them in the context which you are. An appropriate if() would be:

if( $data =~ /\w\w-\d\d-\d{4}/ or $data =~ /\w\d-\d\d-\d{4}/ )

Hope this gets you on your way.

Simon
NB: You can use chdir() if you want to traverse directories in perl.


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

Date: Fri, 18 Jul 1997 00:41:23 GMT
From: over@the.net (dave)
Subject: Re: Using varaibles from a template file
Message-Id: <33ceb97e.7986644@news.one.net>

perrella andrew c <perrella@ehsn28.cen.uiuc.edu> wrote:


>However is I have in the code
>
>print "$template";
>
>I get
>
>hello, 
>	my name is $fname $lname
>
>which is literally the contents of the template file.
>

YOU could also put:


print <<EOFP;
hello,
	my name is \u$fname \u$lname
EOFP


in the template file, then use:

do "$template";

to execute the template file after you have set the variables.  The
names will not only be substituted, but also have the first letters
always uppercase.

If tainting is enabled, you may have to check and untaint $template.
Also include a directory specification in the do, even it if is "./".



Dave
|
| Please visit me at http://w3.one.net/~dlripber
|
| For reply by email, use:
| dlripber@one.net
|________


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

Date: Thu, 17 Jul 1997 10:27:20 -0400
From: "James J. Heck" <jheck@merck.com>
Subject: Re: What is--->>  19.483u 0.216s 0:12.71 154.9% 0+0k 0+0io 0pf+0w
Message-Id: <33CE2BC8.167E@merck.com>

squeak! wrote:
> 
> On Thu, 17 Jul 1997, Shaun O'Shea wrote:
> 
> > Sometimes when I run perl scripts , the output gets spewed out and then
> > stalls and finally spits out something similar to:
> >
> >       19.483u 0.216s 0:12.71 154.9% 0+0k 0+0io 0pf+0w
> >
> > Usually this occurs when the perl script contains nested loops.
> 
> I have no idea *why* it does this, but that's the time that's passed since
> 00:00:00 Jan 1, 1970.

	Actually this looks like the output of a "time" command. The format is:

The command is executed; after it is complete, time prints the elapsed
time during the command, the time spent in the system, and the time
spent
in execution of the command.  Times are reported in seconds.

	Hope this helps.

James

--------------------
James J. Heck
jheck@acm.org
http://www.bucknell.edu/~jheck


       The contents of this message express only the sender's opinion.
       This message does not necessarily reflect the policy or views of
       my employer, Merck & Co., Inc.  All responsibility for the statements
       made in this Usenet posting resides solely and completely with the
       sender.


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

Date: Thu, 17 Jul 1997 09:21:21 +0100
From: Simon Fairey <sfairey@adc.metrica.co.uk>
To: touvetcl@nortel.com
Subject: Re: Where can I find Perl?
Message-Id: <33CDD601.167E@adc.metrica.co.uk>

Clotilde Touvet wrote:
> 
> I have received a program written using a Perl script, and I do not have
> Perl on my machine.  I absolutely need to run it but I do not know where
> to get Perl from.  Can anyone help me?
> Also, I do not have a unix machine, but a Dell PC running Windows 95.
> However, I think it is possible to use Perl on this, right?...
> 
> Thanks so much in advance...
> 
> Clotilde

Go to 'http://www.perl.com' you will find all that you need there.

Simon


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

Date: 17 Jul 1997 14:50:33 -0700
From: chrissch@cs.uoregon.edu (Chris Schleicher)
Subject: Re: Where can I find Perl?
Message-Id: <5qm439$qlq@psychotix.cs.uoregon.edu>

In article <33CCF99E.4F1F@nortel.com>,
Clotilde Touvet  <touvetcl@nortel.com> wrote:
>Also, I do not have a unix machine, but a Dell PC running Windows 95. 
>However, I think it is possible to use Perl on this, right?...

Yup.  Visit the center of the Win32Perl universe at

    http://www.activeware.com

to get started.  You'll also find the center of the Perl universe at

    http://www.perl.com/perl

quite useful.


Hope this helps,

--Chris
-- 
     Chris Schleicher                      Office:  541/346-3998
     Univ of Oregon CIS GTF                email: chrissch@cs.uoregon.edu
                URL: http://www.cs.uoregon.edu/~chrissch/


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

Date: Thu, 17 Jul 1997 10:47:20 +0100
From: Simon Fairey <sfairey@adc.metrica.co.uk>
To: sajjad@uic.edu
Subject: Re: Why: @{$_[0]} for arg in subroutine
Message-Id: <33CDEA28.794B@adc.metrica.co.uk>

Sajjad Lateef wrote:
> 
> Hi,
> Check this out:
> #main
> my @color_array = [ 'Red', 'Blue', 'Yellow'];

Using square brackets here means that you are defining an anonymous
array reference so @colour_array actually contains one element which is
a reference to the array with 'Red' etc in. What you want to be using in
standard parentheses i.e:

my @colour_array = ( 'Red', 'Blue', 'Yellow' );

> 
> &callsub(@color_array);
> ...
> sub callsub {
> my @list = @{$_[0]};

Having done the above then you can write:

my @list = @_;

Also remember if you want the changes made to the array in the function
to be accessible outside of the function then you need to pass a
reference to the array to the function rather than the whole array, but
that is another story :).

> Any help is appreciated. I want to know why this is happening.

No problem, now you know :)

Simon


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

Date: Thu, 17 Jul 1997 01:35:03 -0700
From: "Mark J. Schaal" <mark@tstonramp.com>
Subject: Re: Why: @{$_[0]} for arg in subroutine
Message-Id: <33CDD937.12F5@tstonramp.com>

Sajjad Lateef wrote:
> 
> my @color_array = [ 'Red', 'Blue', 'Yellow'];
> 
> &callsub(@color_array);
> ...
> sub callsub {
> my @list = @{$_[0]};
> # mess with @list
> }
>
> Now, according to the Camel Book, I can do 'my @list = @_' and then I should
> be able to use @list. I just cannot do that! If I do that, then @list contains
> a hard reference of the type ARRAY(0x12345678).
> I can only use @list if I dereference $_[0] using @{...}.
> 

By using square brackets you are creating a reference.  What you
probably
wanted was to use parenthesis:
	my @color_array = ( 'Red', 'Blue', 'Yellow' );

See the 'perlref' section of the perl documentation for more information
about references.

hope this helps,

mark
--
Mark J. Schaal		TST On Ramp Sysadmin		mark@tstonramp.com


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

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

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