[7073] in Perl-Users-Digest

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

Perl-Users Digest, Issue: 698 Volume: 8

daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Thu Jul 3 12:17:20 1997

Date: Thu, 3 Jul 97 09:00:27 -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           Thu, 3 Jul 1997     Volume: 8 Number: 698

Today's topics:
     Re: ?: How to copy a file? <paulyan@hpcc102.corp.hp.com>
     Easy PERL question <cgs@vip.net>
     Re: forking without wait <merlyn@stonehenge.com>
     Irregular Expression (Art Blair)
     Re: print reverse (Jack Applin)
     Printing to a serial port duplicates first 4k, then OK (Greg Mortensen)
     Re: Require Problem <merlyn@stonehenge.com>
     Running script fragment in different file, same context (dave)
     simple script? <mstan@tally.uchsc.edu>
     TOP 5 PERL FEATURES THAT DON'T PORT TO NT (dave)
     TOP 5 REASONS FOR SWITCHING TO PERL (dave)
     Re: TOP 5 REASONS FOR SWITCHING TO PERL (Nathan V. Patwardhan)
     Re: Trouble with Split command (Matthew Cravit)
     Re: Trouble with Split command (M. muPe)
     Re: What does this do? (Tung-chiang Yang)
     Re: what is my, lc and etc and where to learn it? (A. Deckers)
     Digest Administrivia (Last modified: 8 Mar 97) (Perl-Users-Digest Admin)

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

Date: Wed, 02 Jul 1997 10:02:28 -0700
From: Paul Yan <paulyan@hpcc102.corp.hp.com>
Subject: Re: ?: How to copy a file?
Message-Id: <33BA89A4.6136@hpcc102.corp.hp.com>

Brent Michalski wrote:
> 
> If it is a UNIX box, you should be able to just put a `cp file1 file2`;
> into your script.
> 
> --
> ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
> ~ Currently a Webmaster in the Air Force                 ~
> ~ http://www.ellsworth.af.mil                            ~
> ~ Air Force Web Site of the Month for April!             ~
> ~ Looking for a job that actually pays!                  ~
> ~ Resume at: http://www.rapidcity.com/~brent/resume.html ~
> ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
You can write a program by yourself. Use read() and write() call. 
Remember set your file mode to binary use binmode()


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

Date: Wed, 02 Jul 1997 17:25:47 -0700
From: Customer Service <cgs@vip.net>
Subject: Easy PERL question
Message-Id: <334ED684.48A4@vip.net>

How do I seek the last record and add  to the end of an ascii
file?
I know seek(VFILE, 0, 0); gets me to the first record, how do I
add another line?

Thanks

-- 
Chris /	cgiroux@vip.net

www.KOSMONET.com / contact@kosmonet.com / 1-888-4KOSMOS


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

Date: 02 Jul 1997 17:22:56 -0700
From: Randal Schwartz <merlyn@stonehenge.com>
To: Pete Williams <petew@lexis-nexis.com>
Subject: Re: forking without wait
Message-Id: <8chgedc7bz.fsf@gadget.cscaper.com>

>>>>> "Pete" == Pete Williams <petew@lexis-nexis.com> writes:

Pete> You'll have to use a fork-exec thing with a trailing waitpid() in the
Pete> parent, like follows:

Pete> require 'sys/wait.h'; # or "use POSIX ':sys_wait_h';
Pete> $kidpid = fork;
Pete> if ($kidpid == 0) {
Pete> 	exec @cmd;
Pete> }
Pete> waitpid($kidpid,WNOHANG);

This is dangerous if fork returns undef.  Which it might if forking is
either temporarily or permanently failing.

print "Just another Perl hacker," # but not what the media calls "hacker!" :-)
## legal fund: $20,495.69 collected, $182,159.85 spent; just 425 more days
## before I go to *prison* for 90 days; email fund@stonehenge.com for details

-- 
Name: Randal L. Schwartz / Stonehenge Consulting Services (503)777-0095
Keywords: Perl training, UNIX[tm] consulting, video production, skiing, flying
Email: <merlyn@stonehenge.com> Snail: (Call) PGP-Key: (finger merlyn@ora.com)
Web: <A HREF="http://www.stonehenge.com/merlyn/">My Home Page!</A>
Quote: "I'm telling you, if I could have five lines in my .sig, I would!" -- me


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

Date: 3 Jul 1997 00:26:32 GMT
From: blair@sf73.dseg.ti.com (Art Blair)
Subject: Irregular Expression
Message-Id: <5perjo$pjj@sf18.dseg.ti.com>

Lets say I want to find all instances of foobar in the following text:

the magic woid is foobar
with a fontchange it's (foo)\bold(bar)
bar food is crude.

and I even want to find any instance where there might be
up to 10 characters of junk between foo & bar (like in a 
postscript file) as in the 2nd line. 
I could match it with
/foo.*?bar/ 
but thats inefficent. That * will go on to the end of what may be a 
huge file. I know there will only be up to 10 chars
of junk between foo & bar. It seems like
/foo.{0,10}?bar/
would work but it doesn't match any of them.
Why ?

I'm using perl 5.003 but it doesn't work with egrep either. So
I think the bug is in my head, not perl.
Art.


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

Date: 3 Jul 1997 01:45:57 GMT
From: neutron@fc.hp.com (Jack Applin)
Subject: Re: print reverse
Message-Id: <5pf08l$d94@fcnews.fc.hp.com>

Zisha Weinstock wrote:

> $foo = reverse("12345");
> print $foo;
> 
> prints 54321
> 
> print reverse("12345");
> 
> prints 12345. Why?
> 

In a print statement, reverse is in list context.  In a list context,
reverse reverses its list of arguments.  Since you gave it one argument,
the reverse of that list is pretty much what you started out with.
To do what you wanted, force a scalar context, like this:

	print scalar(reverse("12345"));


				-Jack Applin
				 neutron@fc.hp.com


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

Date: Thu, 3 Jul 1997 01:44:49 GMT
From: loki@world.std.com (Greg Mortensen)
Subject: Printing to a serial port duplicates first 4k, then OK
Message-Id: <ECpzIq.n15@world.std.com>

Greetings. I have a seemingly simple question, which doesn't appear to be
covered by the Camel book (either version :), or the FAQ, so here goes:

I have two computers connected via a null-modem cable.  I'm trying to copy
a file between the two, using their serial ports.  The following code
snippet works if I'm copying from a file --> to a file, or via sockets,
but it "works" in a strange way over a serial line.  (I'm using Linux
2.0.30):

----------
system "stty raw < /dev/ttyS0";            # Set up the port... More
system "stty crtscts 19200 < /dev/ttyS0";  # portable than ioctl

open(PORT, "< /dev/ttyS0") || die "cant open";

while(<PORT>){
  print;
}
----------

On the sending side, I set up the port in a similar manner (turning on
hardware flow control), and do a "cat ascii_text_file > /dev/..."

On the perl (receiving) side this happens:  The first 4k (or so) prints to
STDOUT just fine, then it repeats the first 4k (with Control-J's this
time), then the rest of the file prints without any problems.  What could
be causing this? I've tried turning buffering off, turning it back on,
sending with a terminal program, ad infinitum.

Solutions?  I've tried following the Camel book (even where it contradicts
itself :) to no avail.  Any pointers would be appreciated.
-- 
\|/   ___   \|/        loki@world.std.com        +----- 2048/83C90191 -----+
 @~./'O o`\.~@                                   | 0B 65 E0 58 F3 F9 81 F5 |
/__( \___/ )__\  Crypto, Security, and Phrack:   | F0 72 75 FA 1E BD C9 66 |
   `\__`U_/'       http://world.std.com/~loki    +--- via Finger or WWW ---+


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

Date: 02 Jul 1997 17:26:55 -0700
From: Randal Schwartz <merlyn@stonehenge.com>
To: xewj@odin.sunquest.com
Subject: Re: Require Problem
Message-Id: <8cen9hc75c.fsf@gadget.cscaper.com>

>>>>> "xewj" == xewj  <xewj@odin.sunquest.com> writes:

xewj> While a RTFM response is completely justified in this case,
xewj> here's the answer: add "1;" to the end of your taggerlibrary.pm
xewj> file.

xewj> Why? Because someplace, somewhere, the documentation says it
xewj> is. Bloody heck, I looked through the manpages and couldn't find
xewj> it. I know it's in the camel book, though. Maybe the local
xewj> manpages are old...  Ah well, RTFM if you know the reference
xewj> (grin).

"man perlfunc" says (in part) near the "require" item:

perlfunc>              Note that the file will not be included twice under
perlfunc>              the same specified name.  The file must return TRUE
perlfunc>              as the last statement to indicate successful
perlfunc>              execution of any initialization code, so it's
perlfunc>              customary to end such a file with "1;" unless you're
perlfunc>              sure it'll return TRUE otherwise.  But it's better
perlfunc>              just to put the "1;", in case you add more
perlfunc>              statements.

print "Just another Perl hacker," # but not what the media calls "hacker!" :-)
## legal fund: $20,495.69 collected, $182,159.85 spent; just 425 more days
## before I go to *prison* for 90 days; email fund@stonehenge.com for details

-- 
Name: Randal L. Schwartz / Stonehenge Consulting Services (503)777-0095
Keywords: Perl training, UNIX[tm] consulting, video production, skiing, flying
Email: <merlyn@stonehenge.com> Snail: (Call) PGP-Key: (finger merlyn@ora.com)
Web: <A HREF="http://www.stonehenge.com/merlyn/">My Home Page!</A>
Quote: "I'm telling you, if I could have five lines in my .sig, I would!" -- me


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

Date: Thu, 03 Jul 1997 00:34:28 GMT
From: over@the.net (dave)
Subject: Running script fragment in different file, same context
Message-Id: <33baf131.4582337@news.one.net>

A quick look thru the camel book led me to believe the easiest way to
execute a script fragment contained in another file, within the same
context as the main script, was to open and read the file lines into a
string variable, then eval the string variable.  Turns out I also had
to match a reg expression to the string variable and use the matched
variable because the original string variable was tainted.

Is there an easier way that I stupidly overlooked?


Thanks,
Dave

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


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

Date: Wed, 02 Jul 1997 17:40:30 -0700
From: Michael Tan <mstan@tally.uchsc.edu>
Subject: simple script?
Message-Id: <33BAF4FE.475D@tally.uchsc.edu>

can anyone supply me with a script that will 'mv' the .extensions of 
certain files?

e.g.  

file1.seq
file2.seq
file3.seq
file4.seq
 ...

move all the file(n).seq --> file(n).seq.x
file1.seq.x
file2.seq.x
file3.seq.x
file4.seq.x



thanks for any help!



~~~~~~~~~~~~~~~~~~~~~~~~
Michael Tan
UCHSC School of Medcine
Department of Pharmacology
Denver, CO 80262


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

Date: Thu, 03 Jul 1997 01:13:56 GMT
From: over@the.net (dave)
Subject: TOP 5 PERL FEATURES THAT DON'T PORT TO NT
Message-Id: <33bafc58.7437119@news.one.net>

Hi,

Me again needing some quick reliable info.  What are the main features
of perl running on Unix that aren't ported to Windows NT?

Thanks,
Dave

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


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

Date: Wed, 02 Jul 1997 23:43:31 GMT
From: over@the.net (dave)
Subject: TOP 5 REASONS FOR SWITCHING TO PERL
Message-Id: <33bae5a2.1623088@news.one.net>


Excuse the caps, but I REALLY need some assistance!

I did some Web programming in perl and fell in love with it like so
many other people.  So I took it to work and began using it instead of
ksh.  Also downloaded the Tk extension and did a trial application.

Now I need to present it to the rest of the software programmers that
use ksh and haven't tried perl.

I'm hoping some more experienced perl programmers in this newsgroup
can tell me the main reasons why someone should switch from ksh/csh
scripts to perl scripts.


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


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

Date: 3 Jul 1997 01:07:05 GMT
From: nvp@shore.net (Nathan V. Patwardhan)
Subject: Re: TOP 5 REASONS FOR SWITCHING TO PERL
Message-Id: <5petvp$mj9@fridge-nf0.shore.net>

dave (over@the.net) wrote:

: I'm hoping some more experienced perl programmers in this newsgroup
: can tell me the main reasons why someone should switch from ksh/csh
: scripts to perl scripts.

csh is like a bomb waiting to go off.  There's more CERT advisories
about csh than one can imagine.  Don't use it if you can avoid it.

--
Nathan V. Patwardhan
nvp@shore.net



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

Date: 2 Jul 1997 17:14:51 -0700
From: mcravit@best.com (Matthew Cravit)
Subject: Re: Trouble with Split command
Message-Id: <5peqtr$da1$1@shell3.ba.best.com>

In article <01bc872c$7ef49440$c61012ac@sloscialo.chubb.com>,
Sergio Loscialo <nospam_sloscialo@chubb.com_nospam> wrote:
>I am having trouble using the split command with the following syntax:
>   $s = 'PWNT803;P08;Aug. 1, 12, 14 (eves. M, T, Th. & Sat. Aug. 16)';
>  @vals = split /;/, $s;
>
>I figured I would get an array of length 3, but for some reason the command
>is also splitting on the commas.

What version of perl are you using? I just tried this on my system, with
both perl 5.003 and 5.004, and if I do:

    $s = 'PWNT803;P08;Aug. 1, 12, 14 (eves. M, T, Th. & Sat. Aug. 16)';
    @vals = split /;/, $s;
    foreach $i (0..$#vals) {
        print "vals[$i] = \"$vals[$i]\"\n";
    }

I get the following output:

    vals[0] = "PWNT803"
    vals[1] = "P08"
    vals[2] = "Aug. 1, 12, 14 (eves. M, T, Th. & Sat. Aug. 16)"

So, it seems to work fine for me. One thing you might try doing is to
change your split line to:

	@vals = split(/;/, $s, 3);

Perhaps the explicit parentheses, plus the explicit "stuff everything atfer
the second semicolon into the third field" will help you.

/MC

-- 
--
Matthew Cravit, N9VWG               | Experience is what allows you to
E-mail: mcravit@best.com (home)     | recognize a mistake the second
        mcravit@taos.com (work)     | time you make it.


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

Date: Thu, 03 Jul 1997 01:08:33 GMT
From: mupe@desk.nl (M. muPe)
Subject: Re: Trouble with Split command
Message-Id: <5peqpb$9hq$2@news2.xs4all.nl>

In article <01bc872c$7ef49440$c61012ac@sloscialo.chubb.com>, "Sergio Loscialo" <nospam_sloscialo@chubb.com_nospam> wrote:
>I am having trouble using the split command with the following syntax:
>   $s = 'PWNT803;P08;Aug. 1, 12, 14 (eves. M, T, Th. & Sat. Aug. 16)';
>  @vals = split /;/, $s;
>

Try the more explicite over-correct way;
@vals = split(/\;/, $s);

Mathilde muPe


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

Date: Thu, 3 Jul 1997 01:18:29 GMT
From: tcyang@netcom.com (Tung-chiang Yang)
Subject: Re: What does this do?
Message-Id: <tcyangECpyAt.2z5@netcom.com>

That statement with 'pack' is used in typical CGI scripts.  Usually
you have the following codes:

   $search_target =~ tr/+/ /;
   $search_target =~ s/%([\dA-Fa-f][\dA-Fa-f])/pack("C", hex($1))/eg;

to extract information submitted in a CGI form with Perl, because
some special characters are replaced with their encoded versions.  Read
the O'Reilly book on CGI programming by Shirshim(?) for details.

============================================
M. muPe wrote after talking to Zeus and Hercules:
: In article <33BA7D05.3EAA@storm.simpson.edu>, schneide@storm.simpson.edu wrote:
: >I'm fairly new to Perl and I'm trying to debug a script written by the
: >person I replaced.  Could somebody "interpret" the following line:
: >
: >$name =~ s/%([a-fA-F0-9][a-fA-F0-9])/pack("C", hex($1))/eg;
: >
: >Thanks in advance.

: That matches a hex number and replaces it with ...
: pack("C", hex($1)) 
: hex($1) convert the hex number stored in temporay var $1 to decimal
: pack("C", ..) converts to unsigned char (0 to 255)

: I'm not a Perl wizard, but expecting a function to be executed in the
: replacement part seems very exotic. 

--
========= Try the low-crossposting robomoderated 'alt.culture.taiwan' ===

soc.culture.taiwan, soc.culture.china (by SCC FAQ Team) FAQ's:
   http://www.iglou.com/tcyang/Taiwan_faq.shtml, China_faq.shtml


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

Date: 3 Jul 1997 00:40:26 GMT
From: deckers@man.ac.uk (A. Deckers)
Subject: Re: what is my, lc and etc and where to learn it?
Message-Id: <slrn5rlt75.ktl.deckers@nessie.mcc.ac.uk>

In <Pine.SOL.3.95.970623215255.15875A-100000@lily>,
	mike mah <esupu@warwick.ac.uk> wrote:
>hi perl gurus,
>	I feel so strange, you know. Although I finished reading Learning
>Perl, I never encounter my, lc and etc. Why is that so? Where can I get to
>learn complete (probably advance features) set of command (like above)?

Buy "Programming Perl" (2nd Ed.), also known as the Camel Book. Or
check the voluminous ammounts of free documentation that are
distributed with the Perl source. If you can't find the docs on your
system, check the URLs in my .sig. In fact, check them even if you do
find the docs on your system. :-)

HTH,

Alain

-- 
Perl information: <URL:http://www.perl.com/perl/>
        Perl FAQ: <URL:http://www.perl.com/perl/faq/>
    Perl archive: <URL:http://www.perl.com/CPAN/>
>>>>>>>> comp.lang.perl.misc is NOT a CGI group <<<<<<<<<<


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

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

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