[12105] in Perl-Users-Digest

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

Perl-Users Digest, Issue: 5705 Volume: 8

daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Mon May 17 20:07:10 1999

Date: Mon, 17 May 99 17:00:22 -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, 17 May 1999     Volume: 8 Number: 5705

Today's topics:
    Re: clearing the screnn <cassell@mail.cor.epa.gov>
    Re: creating raw sockets with pack <cassell@mail.cor.epa.gov>
    Re: Error message when reading a file tcpeter@my-dejanews.com
    Re: FAQ 4.15: How do I find yesterday's date? (John Stanley)
    Re: FAQ 4.15: How do I find yesterday's date? (Chris Nandor)
    Re: FAQ 4.15: How do I find yesterday's date? (John Stanley)
    Re: FAQ 4.36: Why don't my E<lt>E<lt>HERE documents wor (John Stanley)
    Re: FAQ 4.36: Why don't my E<lt>E<lt>HERE documents wor (Chris Nandor)
    Re: FAQ 4.36: Why don't my E<lt>E<lt>HERE documents wor (John Stanley)
    Re: free cgi hosting dalehend@flash.net
    Re: Generating data from regular expressions <stevem@rational.REMOVE.com>
        help needed tex2121@my-dejanews.com
    Re: help, A Simple Question (Sam Holden)
    Re: How to pass params by ref/addr into subroutines <medim@beyond.com>
    Re: How to pass params by ref/addr into subroutines <microchip@centuryinter.net>
    Re: How to pass params by ref/addr into subroutines (Andrew Allen)
        how to read in line by line? <yangc@ra.comm.mot.com>
    Re: I need some help tex2121@my-dejanews.com
    Re: man pages and FAQs: why posted? (John Stanley)
    Re: man pages and FAQs: why posted? (John Stanley)
    Re: man pages and FAQs: why posted? (John Stanley)
    Re: Monadic classes, eponymous metaobjects, and translu <emschwar@rmi.net>
    Re: Newbie: Aligning Text in Output File (Larry Rosler)
    Re: Newbie: Aligning Text in Output File <cassell@mail.cor.epa.gov>
    Re: Off-topic: France (was Re: Perl "constructors") <josh@netoutfit.com>
    Re: OOP and Perl-a good book? (Damian Conway)
    Re: Parsing a data file... dana@oz.net
    Re: Passing references <aqumsieh@matrox.com>
    Re: PERLFUNC: opendir - open a directory (Andrew Allen)
    Re: regexp problem <aqumsieh@matrox.com>
        Using split with map, then join lou@visca.com
    Re: Using split with map, then join <ebohlman@netcom.com>
        Special: Digest Administrivia (Last modified: 12 Dec 98 (Perl-Users-Digest Admin)

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

Date: Mon, 17 May 1999 15:39:56 -0700
From: David Cassell <cassell@mail.cor.epa.gov>
Subject: Re: clearing the screnn
Message-Id: <37409ABC.4925A83C@mail.cor.epa.gov>

Gary Yerby wrote:
> 
> does anyone know the statement to clear what the user sees on the screen so
> as to have a nice clean screen for the next statement.

Actually, a lot of people know.  Because it's a FAQ.  Please
check out the FAQ and the programs which give you access to it.
If you are unfamiliar with said programs (like perldoc), you
might like to read this article:
   http://www.perlmonth.com/articles//rtfm.html

Then you can effectively find the answer using:
   perldoc -q [keyword]

where [keyword] is something that makes sense, like, say
"clear" or "screen".

You'll find that learning to use the Perl docs will make you
a better Perl programmer, will make you happier (since rude
know-it-alls won't be insulting you for not reading the FAQ
before posting), and will make things faster (you won't have
to wait hours or days to get a possibly incomplete or
incorrect answer).  All in all, a win-win situation.  People
here have devoted literally man-years to writing and main-
taining all the Perl docs, and tend to see questions like
yours as 'not doing your homework first'.
 
HTH,
David
-- 
David Cassell, OAO                     cassell@mail.cor.epa.gov
Senior computing specialist
mathematical statistician


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

Date: Mon, 17 May 1999 15:05:18 -0700
From: David Cassell <cassell@mail.cor.epa.gov>
Subject: Re: creating raw sockets with pack
Message-Id: <3740929E.7EFC38B2@mail.cor.epa.gov>

Corey Saltiel wrote:
> 
> Greetings,
> 
>   I'm a complete novice to network socket programming and would like
>   to learn using perl.  I'm pretty confident as a perl programmer,
>   and where/how/which docs to read for info - but I could really use
>   some pointers on the creation of raw headers/ ip packets.  Looking
>   at the net modules code with the standard lib in perl I see the
>   use of the 'pack' function, however reading 'perldoc -f pack' leaves
>   me totally in the dust, as it does nothing to explain to explain
>   the purpose/method of it's use in the creation of raw sockets.
> 
>   If anyone would be so kind as to give me an example of some code generating
>   a standard ip header and explaining it - I would appreciate it emmensely.
> 
>   Or even just giving me some pointers to any perl related documentation on
>   this specific topic.
> 
>   Thanks a bunch.

While you'll be able to find snippets here and there in the 
docs, the best Perl+sockets discussion I have handy is chapter
17 of the ram: the "Perl Cookbook" by Tom Christiansen and
Nathan Torkington.  You can glom onto bits of code, but for
a larger explanation, you'll want their book.. and possibly
one of the many books and refs they point out in their intro
to the chapter.

BTW, it has a great quote at the chapter start as well.
Don't skip over that.

David
-- 
David Cassell, OAO                     cassell@mail.cor.epa.gov
Senior computing specialist
mathematical statistician


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

Date: Mon, 17 May 1999 21:57:23 GMT
From: tcpeter@my-dejanews.com
Subject: Re: Error message when reading a file
Message-Id: <7hq3c2$3tr$1@nnrp1.deja.com>

Got it!  Here's the new code:

#! /usr/bin/perl -w

open(FILE,">>match.txt") || die "Couldn't open file match.txt : $! \n";
print "What text are you looking for? \n";
chomp (my $text = <STDIN>);
for my $filename (<*>) {
	open(TRIAL,"$filename");
	while (<TRIAL>){
		print FILE "$filename \n" if /$text/;
		}
}
close(FILE);

There are still some things I'm going to improve, like the fact that
this will write the filename for each occurrence of $text in the file.
That could actually be a benefit once I've finished the script, since
I'd like to use it as a global search and replace across multiple files
containing various text.  For instance, I'd like to find all HTML
documents that have Untitled or Untitled Document in the title tag, and
replace it with the name of the file.  This is a huge step in the
right direction.  Thanks for all the help.

 In article <7hq0f5$1pc$1@nnrp1.deja.com>,
  Dick Latshaw <latsharj@my-dejanews.com> wrote:
> take a look at: for my $filename (<*>) {
>


--== Sent via Deja.com http://www.deja.com/ ==--
---Share what you know. Learn what you don't.---


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

Date: 17 May 1999 22:42:39 GMT
From: stanley@skyking.OCE.ORST.EDU (John Stanley)
Subject: Re: FAQ 4.15: How do I find yesterday's date?
Message-Id: <7hq60v$s59$1@news.NERO.NET>

In article <373b9118@cs.colorado.edu>,
Tom Christiansen  <perlfaq-suggestions@perl.com> wrote:
>(This excerpt from perlfaq4 - Data Manipulation 
>    ($Revision: 1.46 $, $Date: 1999/04/20 18:59:53 $)
>part of the standard set of documentation included with every 
>valid Perl distribution, like the one on your system.
>See also http://language.perl.com/newdocs/pod/perlfaq4.html
>if your negligent system adminstrator has been remiss in his duties.)
>
>  How do I find yesterday's date?
>
>    The `time()' function returns the current time in seconds since the
>    epoch. Take one day off that:
>
>        $yesterday = time() - ( 24 * 60 * 60 );

Except that 24*60*60 isn't always "one day", and thus can give the wrong
answer. Refer to DejaNews for a more complete discussion of this
problem, which takes place in this group on a regular basis.



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

Date: Mon, 17 May 1999 22:58:08 GMT
From: pudge@pobox.com (Chris Nandor)
Subject: Re: FAQ 4.15: How do I find yesterday's date?
Message-Id: <pudge-1705991858090001@192.168.0.77>

In article <7hq60v$s59$1@news.NERO.NET>, stanley@skyking.OCE.ORST.EDU
(John Stanley) wrote:

# In article <373b9118@cs.colorado.edu>,
# Tom Christiansen  <perlfaq-suggestions@perl.com> wrote:
# >(This excerpt from perlfaq4 - Data Manipulation 
# >    ($Revision: 1.46 $, $Date: 1999/04/20 18:59:53 $)
# >part of the standard set of documentation included with every 
# >valid Perl distribution, like the one on your system.
# >See also http://language.perl.com/newdocs/pod/perlfaq4.html
# >if your negligent system adminstrator has been remiss in his duties.)
# >
# >  How do I find yesterday's date?
# >
# >    The `time()' function returns the current time in seconds since the
# >    epoch. Take one day off that:
# >
# >        $yesterday = time() - ( 24 * 60 * 60 );
# 
# Except that 24*60*60 isn't always "one day", and thus can give the wrong
# answer. Refer to DejaNews for a more complete discussion of this
# problem, which takes place in this group on a regular basis.

But time() - (24*60*60) will always give you the previous day.  Since we
are looking for a date, not a specific time, it is sufficient.

-- 
Chris Nandor          mailto:pudge@pobox.com         http://pudge.net/
%PGPKey = ('B76E72AD', [1024, '0824090B CE73CA10  1FF77F13 8180B6B6'])


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

Date: 17 May 1999 23:46:37 GMT
From: stanley@skyking.OCE.ORST.EDU (John Stanley)
Subject: Re: FAQ 4.15: How do I find yesterday's date?
Message-Id: <7hq9ot$1cv$1@news.NERO.NET>

In article <pudge-1705991858090001@192.168.0.77>,
Chris Nandor <pudge@pobox.com> wrote:
>In article <7hq60v$s59$1@news.NERO.NET>, stanley@skyking.OCE.ORST.EDU
>(John Stanley) wrote:
>But time() - (24*60*60) will always give you the previous day.  Since we
>are looking for a date, not a specific time, it is sufficient.

Please refer to any of the multitude of discussions that have covered
this subject to death for an example of when your claim is not true. Or,
run this small perl script and see that the simple calculation is not
always the right calculation.

The short version is, as just one example, that at 11:30PM on Oct 25, 1998,
the date (24*60*60) seconds earlier was still Oct 25.  

#!/usr/local/bin/perl5

require "timelocal.pl";
$when = &timelocal( 0, 30, 23, 27, 9, 98 );
$count = 6;

while( $count-- ) {
        $c = scalar localtime($when);
        print $c . " \n";
        $when -= 24*60*60;
}



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

Date: 17 May 1999 22:48:22 GMT
From: stanley@skyking.OCE.ORST.EDU (John Stanley)
Subject: Re: FAQ 4.36: Why don't my E<lt>E<lt>HERE documents work?
Message-Id: <7hq6bm$sfe$1@news.NERO.NET>

Subject: Re: FAQ 4.36: Why don't my E<lt>E<lt>HERE documents work?  

Please, please, please. I am asking as nicely as I can. Please post
these with correct and valid subjects. The Subject is the ONLY place
where the question and its number appear, and is the only place to 
rebuild the index from. 

Why don't your E<lt>E<lt>HERE docs work? Because it is a syntax error.
You've included what appears to be formatting to cause emphasis(?) of
the '<' symbol, which needs no emphasis.



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

Date: Mon, 17 May 1999 22:56:16 GMT
From: pudge@pobox.com (Chris Nandor)
Subject: Re: FAQ 4.36: Why don't my E<lt>E<lt>HERE documents work?
Message-Id: <pudge-1705991856180001@192.168.0.77>

In article <7hq6bm$sfe$1@news.NERO.NET>, stanley@skyking.OCE.ORST.EDU
(John Stanley) wrote:

# Subject: Re: FAQ 4.36: Why don't my E<lt>E<lt>HERE documents work?  
# 
# Please, please, please. I am asking as nicely as I can. Please post
# these with correct and valid subjects. The Subject is the ONLY place
# where the question and its number appear, and is the only place to 
# rebuild the index from. 
# 
# Why don't your E<lt>E<lt>HERE docs work? Because it is a syntax error.
# You've included what appears to be formatting to cause emphasis(?) of
# the '<' symbol, which needs no emphasis.

No, E<lt> means to use the less-than symbol.  It is POD markup, and is the
correct header for that FAQ.  There is no syntax error there, it is just
POD.

-- 
Chris Nandor          mailto:pudge@pobox.com         http://pudge.net/
%PGPKey = ('B76E72AD', [1024, '0824090B CE73CA10  1FF77F13 8180B6B6'])


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

Date: 17 May 1999 23:29:40 GMT
From: stanley@skyking.OCE.ORST.EDU (John Stanley)
Subject: Re: FAQ 4.36: Why don't my E<lt>E<lt>HERE documents work?
Message-Id: <7hq8p4$pd$1@news.NERO.NET>

In article <pudge-1705991856180001@192.168.0.77>,
Chris Nandor <pudge@pobox.com> wrote:
>No, E<lt> means to use the less-than symbol.  It is POD markup, and is the
>correct header for that FAQ.  There is no syntax error there, it is just
>POD.

Except this is USENET, and a USENET message header. It is not POD. It is
simple text. There is no reason to believe that anyone pipes their
news or mail through a POD parser before reading it, and doing so would
most likely cause havok with whatever was being read.

But the bottom line is, it isn't necessary. 



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

Date: Mon, 17 May 1999 23:37:36 GMT
From: dalehend@flash.net
Subject: Re: free cgi hosting
Message-Id: <3740a841.14475484@news.flash.net>




virtualave.com




On Mon, 17 May 1999 22:36:14 +0100, "Tim Shapcott"
<tim.shapcott@NOSPAMvirgin.net> wrote:

>Hi,
>Does anyone know of anywhere that I can ftp my cgi's for free? My isp won't
>host cgi scripts, which is where the site is located. I have found plenty of
>people who will host their own scripts for you, but i can't find any that
>will host my scripts. I really don't want to have to pay for the privilege
>(i know i know), so any help would be appreciated.
>
>Thanks
>
>Tim Shapcott
>
>



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

Date: Mon, 17 May 1999 15:51:28 -0700
From: Steve Moore <stevem@rational.REMOVE.com>
Subject: Re: Generating data from regular expressions
Message-Id: <37409D6F.C962B44D@rational.REMOVE.com>

Oh, sorry, forgot to mention that there would be external controls on how
many data elements to generate. I was more interested in the reverse
operation of pattern matching -- instead of starting with the data in
question and determining if it matches the pattern, start with the pattern
and generate a random string that matches it. I didn't want to invent it from
scratch if I didn't have to.
Thanks.

Steve Moore
Rational Software Corp.

Tad McClellan wrote:

> Steve Moore (stevem@rational.REMOVE.com) wrote:
>
> : Does anyone know if there is shareware that will generate data based on
> : a regular expression?
>
>    What would you have it generate?
>
>       /.*/s
>
>    That is going to generate a rather large list...
>
> --
>     Tad McClellan                          SGML Consulting
>     tadmc@metronet.com                     Perl programming
>     Fort Worth, Texas





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

Date: Mon, 17 May 1999 23:22:11 GMT
From: tex2121@my-dejanews.com
Subject: help needed
Message-Id: <7hq8b1$7hi$1@nnrp1.deja.com>

I am trying to write a program that counts the m most frequent n word
sequences in a text file.  I am close, but I am not getting exactly
what I want.  I have it print in one location to see what my sequences
look like and some are the correct length, and others are either two
large by say two words at the most, or the others are to small by 3 at
the most.(From what I have experienced from testing it)  I can't seem
to find my error, if anyone can help, I would appreciate it.

The command line looks like this: perl program m n filename.txt

here is the code.  Thanks.

# User must pass the n for most frequent, m word sequneces, filenames.
my $numofseq = @ARGV[0] || die "Please enter how many most frequent
							sequences you
want.";
my $mwordseq = @ARGV[1] || die "Please enter the length of the
sequences.";
my $filename = @ARGV[2] || die "Please pass file name.";
open (FILE, $filename) or die "Can't open input file";

# Read contents of file into a string. Concatinates each line on to
# the end of the string.
while (<FILE>) {
   $contents .= $_;
}
close (FILE);

# Take contents of file and split it on whitespace, then insert into
array.
@wordlist = split (/ /,$contents);

foreach $word (@wordlist) {
   # Remove newlines, punctuation from each line so we can ingore them
later.
   # Replace them with whitespace.
   $word =~ s/[\n|.|,|"|?|>|<|_|-|=|+|`|~|!|@|#|$|%|^|&|*|(|)
|;|:|'|\/|\\]//g;
   push(@wordlist2,$word);
}

# Puts each sequence of m words into a hash
$end = 0;
for ($begin = 0; $end <= $#wordlist2+1; $begin++) {
	 	 $end = $begin+$mwordseq -1;
		 $hash{@wordlist2[$begin..$end]};
		 print $hash{@wordlist2[$begin..$end]},"\n";
                 print @wordlist2[$begin..$end],"\n";
}

I think it may be dying in my hash section.  Just above this line.
Thanks.

ty


--== Sent via Deja.com http://www.deja.com/ ==--
---Share what you know. Learn what you don't.---


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

Date: 17 May 1999 23:28:16 GMT
From: sholden@pgrad.cs.usyd.edu.au (Sam Holden)
Subject: Re: help, A Simple Question
Message-Id: <slrn7k19gg.eu5.sholden@pgrad.cs.usyd.edu.au>

On Mon, 17 May 1999 07:46:13 -0700, Larry Rosler <lr@hpl.hp.com> wrote:
>In article <373ff3b0@news.uk.ibm.net> on Mon, 17 May 1999 13:52:36 
>+0200, Vincent Vanbiervliet <vvb@ibm.net> says...
>> dickyart <dickyart@hkstar.com> wrote in message
>> news:373FD758.A94574AA@hkstar.com...
>...
>> > $B=(10,9,8,7,6,5,4,3,2,1,'BOOM');
>> > @A=$B;
>> Sam's suggestion is the best, but if you want to use $B (a scalar), and
>> convert it into an array, you could use:
>> @A=split /,/, $B;

I just thought I'd mention to reduce my number of glaring errors over
the last few days that I didn't say that at all. I said if you want an 
array use an array. Replace $B with @B.

Then again maybe it was a different Sam...

-- 
Sam

Basically, avoid comments. If your code needs a comment to be
understood, it would be better to rewrite it so it's easier to
understand.	--Rob Pike


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

Date: Mon, 17 May 1999 15:32:03 -0700
From: Medi Montaseri <medim@beyond.com>
Subject: Re: How to pass params by ref/addr into subroutines
Message-Id: <374098E3.1A0D331E@beyond.com>

Assuming you know the difference between "Pass-by-Value" and
"Pass-by-reference",
You'd need to pass a reference to your object (data) if you want changes to be
persistant.

So your code will become

MyFunction( \$var);

See perlfref(1) manpages for more on references and how to dereference them.

Grant Williams wrote:

> Yo!
> I am brandnew to perl.
> Have an assignment to do that basically tests our ability at re's and
> parsing strings etc..
>
> I like many have read documentation on references, subroutines etc. only to
> become more confused.  All I would like to know is how to pass a parameter
> into a subroutine, have some work done on it and returned or changed as in
> the following snippet of code.
>
> this is xxx.pl file
> ----------------------------------------------------------------------------
> -----------
> #!c:/perl/bin
> require "yyy.pl";                              #file with subroutine in it
> (below)
> print "Enter your age>";                #say 5 <enter>
> read (STDIN,$age,2);                    #get input
> chop($age);                                    #take out the return char
> changeage($age);                        #change age by adding 10 to it in
> sub
> print "So your age is $age\n";       #print out $age after it has been
> changed
>                                                           #eg. if you enter
> 5, it will be printed as 15!
>
> ----------------------------------------------------------------------------
> -----------
>
> "this is yyy.pl file"
> #!c:/perl/bin
> sub changeage
> {
>    @_[0] += 10;
> }
> 1;
>
> To be extremely verbose about what i want, you enter say "5" as your age.
> Then this is passed into the sub.   The sub alters the val of the parameter
> by adding 10 to it
> When printed, the val will be 15 instead of 5.
>
> Is there a good faq or doco somewhere which explains to beginners how this
> is done?
>
> Ta in advance
> Grant the grad-dipper

--
-------------------------------------------------------
Medi Montaseri <medim@beyond.com>
Software Engineer, Ext 4348
-------------------------------------------------------




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

Date: Mon, 17 May 1999 19:20:48 -0400
From: MicroChip <microchip@centuryinter.net>
Subject: Re: How to pass params by ref/addr into subroutines
Message-Id: <3740A450.41FC@centuryinter.net>

To the original submitter....
Simply put....

$myVar = "old value";
mySub($myVar);
print $myVar;
sub mySub {
	$_[0] = "new value";
};

in your original code you use @_[0] rather then the proper $_[0]

and before i get flamed by someone, i use this method regularly in
operational code and it works great. the only limitation is that you
cant pass a fixed string to it as in  mySub("hello")

MC

Medi Montaseri wrote:
> 
> Assuming you know the difference between "Pass-by-Value" and
> "Pass-by-reference",
> You'd need to pass a reference to your object (data) if you want changes to be
> persistant.
> 
> So your code will become
> 
> MyFunction( \$var);
> 
> See perlfref(1) manpages for more on references and how to dereference them.
> 
> Grant Williams wrote:
> 
> > Yo!
> > I am brandnew to perl.
> > Have an assignment to do that basically tests our ability at re's and
> > parsing strings etc..
> >
> > I like many have read documentation on references, subroutines etc. only to
> > become more confused.  All I would like to know is how to pass a parameter
> > into a subroutine, have some work done on it and returned or changed as in
> > the following snippet of code.
> >
> > this is xxx.pl file
> > ----------------------------------------------------------------------------
> > -----------
> > #!c:/perl/bin
> > require "yyy.pl";                              #file with subroutine in it
> > (below)
> > print "Enter your age>";                #say 5 <enter>
> > read (STDIN,$age,2);                    #get input
> > chop($age);                                    #take out the return char
> > changeage($age);                        #change age by adding 10 to it in
> > sub
> > print "So your age is $age\n";       #print out $age after it has been
> > changed
> >                                                           #eg. if you enter
> > 5, it will be printed as 15!
> >
> > ----------------------------------------------------------------------------
> > -----------
> >
> > "this is yyy.pl file"
> > #!c:/perl/bin
> > sub changeage
> > {
> >    @_[0] += 10;
> > }
> > 1;
> >
> > To be extremely verbose about what i want, you enter say "5" as your age.
> > Then this is passed into the sub.   The sub alters the val of the parameter
> > by adding 10 to it
> > When printed, the val will be 15 instead of 5.
> >
> > Is there a good faq or doco somewhere which explains to beginners how this
> > is done?
> >
> > Ta in advance
> > Grant the grad-dipper
> 
> --
> -------------------------------------------------------
> Medi Montaseri <medim@beyond.com>
> Software Engineer, Ext 4348
> -------------------------------------------------------

-- 
________________________________
  MicroChip Technical Services
  backwoods [at] backwoods.org


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

Date: 17 May 1999 23:44:05 GMT
From: ada@fc.hp.com (Andrew Allen)
Subject: Re: How to pass params by ref/addr into subroutines
Message-Id: <7hq9k5$bb1$1@fcnews.fc.hp.com>

Medi Montaseri (medim@beyond.com) wrote:
: Assuming you know the difference between "Pass-by-Value" and
: "Pass-by-reference",
: You'd need to pass a reference to your object (data) if you want changes to be
: persistant.

wrong. @_ becomes an alias of your passed-in variables. Changes to
elements of @_ will be reflected in changes to the corresponding
variables passed as parameters.

The code given below does exactly what the author intended.

: > this is xxx.pl file
: > ----------------------------------------------------------------------------
: > -----------
: > #!c:/perl/bin
: > require "yyy.pl";                              #file with subroutine in it
: > (below)
: > print "Enter your age>";                #say 5 <enter>
: > read (STDIN,$age,2);                    #get input
: > chop($age);                                    #take out the return char
: > changeage($age);                        #change age by adding 10 to it in
: > sub
: > print "So your age is $age\n";       #print out $age after it has been
: > changed
: >                                                           #eg. if you enter
: > 5, it will be printed as 15!
: >
: > ----------------------------------------------------------------------------
: > -----------
: >
: > "this is yyy.pl file"
: > #!c:/perl/bin
: > sub changeage
: > {
: >    @_[0] += 10;

I'd probably use $_[0] to be correct here (@_[0] is an array slice, $_[0]
is the 0th element of @_.)

: > }
: > 1;
: >
: > To be extremely verbose about what i want, you enter say "5" as your age.
: > Then this is passed into the sub.   The sub alters the val of the parameter
: > by adding 10 to it
: > When printed, the val will be 15 instead of 5.

That's exactly what this code does. I don't understand what your
question is.

Andrew


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

Date: Mon, 17 May 1999 17:58:47 -0500
From: Yang Chao <yangc@ra.comm.mot.com>
Subject: how to read in line by line?
Message-Id: <37409F26.8795E94C@ra.comm.mot.com>

This is a multi-part message in MIME format.
--------------CF9AFB82F79229F678207C32
Content-Type: text/plain; charset=us-ascii
Content-Transfer-Encoding: 7bit

Hi,

  I am trying to write a piece of perl script to process a file.
I want to open a file and then read from it line by line.
I am trying to use the following perl script, but it seems
it only read in one line out of every two lines.  Please give
me some ideas or suggestions, Thanks!



--------------CF9AFB82F79229F678207C32
Content-Type: application/x-perl;
 name="try.pl"
Content-Transfer-Encoding: 7bit
Content-Disposition: inline;
 filename="try.pl"

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

while (<*.frm>){

  print "Current file $_\n";

  open IN, $_ or die "Open Failed; $!";
  print "Open file $_ \n";

  while (<IN>){

        $line = <IN>;
        print "The current line: $line\n";
        if ($line =~ /^VERSION 4\.00$/ or /^Attribute \w+.*/ ) {
                # ignore.
                next;
        }
  }
} 
 

--------------CF9AFB82F79229F678207C32--



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

Date: Mon, 17 May 1999 23:35:33 GMT
From: tex2121@my-dejanews.com
Subject: Re: I need some help
Message-Id: <7hq946$80b$1@nnrp1.deja.com>


> : It was determined on alt.perl that this was a homework problem.
> : Let's not be helping the poor student, please. :(
To begin with it is not a homework assignment.  I asked a profesor for
some problems.  I am trying to learn perl so that I can apply for a job
a local web company that a friend of mine works at.  The profesor dug
some problems out of a book that he had and that was that.  I have been
working little by little for a while now, and have had some progress,
but not enough to where I thought I would finish. That is when I turned
here.
>    Gak!  Now I feel guilty.
There is no reason to feel guilty because it is not an assignment.


--== Sent via Deja.com http://www.deja.com/ ==--
---Share what you know. Learn what you don't.---


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

Date: 17 May 1999 22:33:19 GMT
From: stanley@skyking.OCE.ORST.EDU (John Stanley)
Subject: Re: man pages and FAQs: why posted?
Message-Id: <7hq5ff$rph$1@news.NERO.NET>

In article <373c9171$0$211@nntp1.ba.best.com>,
John Callender  <jbc@shell2.la.best.com> wrote:
>Lee <rlb@intrinsix.ca> wrote:
>
>> I have been reading this ng for quite a while, and also surmised those same
>> reasons. But I don't think it will be effective, and I think it is an
>> enormous waste of bandwidth.
>
>I think this "enormous waste of bandwidth" charge is suspect. What do
>you really mean by it? That the downloading of the headers for these
>articles consumes too much of your modem connection? 

No, that pushing the same text out onto EVERY USENET system that carries
comp.lang.perl.misc, which most likely has already been installed there,
and which installed copy refers to the version installed on that system
and not to just the most recent version, is a waste of bandwidth.

That pushing the man pages and FAQs out onto those who read the group
by mail and have access to the FAQs and man pages already installed on
their systems is a waste of bandwidth.

>not text, but image binaries. In that context, I don't think Tom's
>auto-postings amount to a hill of beans.

In this newsgroup, they do amount to a hill of beans. What, do you WANT
admins to treat this newsgroup with the same disdain they have for
groups such as alt.binaries.*?

>you may have a point, though your personal definitions of "interesting"
>and "uninteresting" will have to be compared to those of other users of
>the group if any sort of general consensus about whether these articles
>constitute a "waste" (to say nothing of an "enormous waste") is to be
>arrived at. 

As everyone who has every flamed a newbie has said a dozen times, the
documentation is on your system already. That pretty much makes posting
it to this newsgroup on a regular basis a complete waste of bandwidth.

The first time is was posted, the excuse was that it was so errors could
be corrected. I notice that one of the FAQ questions still asks about
code that does not run because it is a syntax error, even though I
posted the correction to it the last time.

>Too often, I think, people either consciously or unconsciously try to
>cloak their personal dislike of a particular sort of Usenet content in
>a mantle of "bandwidth preservation," as if denying the rest of the
>community the opportunity to read articles they themselves find
>uninteresting is some sort of noble impulse aimed at preserving the
>commons.

If I disliked this content so much, why do I make it freely available
by email server to anyone who uses the group by mail?  Why am I going
to spend my time repacking the once-nicely-packed FAQ so these people
can get it when they need it if I dislike the content so much? Why will
I most likely spend more time making the man pages available the same
way?

There IS a difference between the ends and the means. I'm sorry if the
concept of "discussion group" is hard to grasp, but that is what this is
supposed to be.

Why is it that one person with perhaps the most vocal statements about
the noise of this group is the one posting each FAQ question and man
page individually? "This group is too noisy so we had to create
c.l.p.mod, and look, I was right, look how noisy it is now."



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

Date: 17 May 1999 22:36:29 GMT
From: stanley@skyking.OCE.ORST.EDU (John Stanley)
Subject: Re: man pages and FAQs: why posted?
Message-Id: <7hq5ld$rv0$1@news.NERO.NET>

In article <Arved_37-1505991151220001@dyip-106.chebucto.ns.ca>,
Arved Sandstrom <Arved_37@chebucto.ns.ca> wrote:
>From another viewpoint, what Tom is doing is "push" delivery as opposed to
>"pull". 

Untrue. Until the installed perl system starts updating the
documentation automatically from the posted man pages, it will be
neither push nor pull, just "fling". 

And it is still not the right place to do the distribution, even if it
were a good idea.

>Yes, I could get the new docs in an active way. 

So we all have to get them so you don't have to take an active role in
your perl experience.



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

Date: 17 May 1999 22:39:55 GMT
From: stanley@skyking.OCE.ORST.EDU (John Stanley)
Subject: Re: man pages and FAQs: why posted?
Message-Id: <7hq5rr$s4k$1@news.NERO.NET>

In article <373EEB15.ABC3D1B6@home.com>,
Rick Delaney  <rick.delaney@home.com> wrote:
>Tom Christiansen wrote:
>> I am trying, you know.
>
>As Larry said, it is appreciated.  Is there something we (the clpm
>community) can do to help you out?  

Yes. If you need an ftp site to keep this material on so people can get
it when they want it, I would be more than happy to help. Ditto web. I
am already keeping them at ftp://ruby.oce.orst.edu:/pub/perl/faqparts
and ftp://ruby.oce.orst.edu:/pub/perl/functions. So, once you complete
this cycle, they are available to anyone.



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

Date: 17 May 1999 17:58:21 -0600
From: Eric The Read <emschwar@rmi.net>
Subject: Re: Monadic classes, eponymous metaobjects, and translucent data members
Message-Id: <xkf3e0vjlk2.fsf@valdemar.col.hp.com>

Tom Christiansen <tchrist@mox.perl.com> writes:
> I'll think about it, but I don't find singleton as appealing as either
> of my suggestions.  It reminds me of someone who can't get a date,
> or something to short-suit into the blind.  I'd rather use highlander,
> since THERE CAN BE ONLY ONE. :-)

Well, the Patterns book by the Gang of Four uses "singleton".  You're
hardly obliged to follow their lead, but using it would reinforce the
notion for people who have read it (i.e., anybody serious about OO), and
is pretty intuitive for those who haven't (at least, it was for me).

And besides, picking highlander would be bad, since there was more than
one (unfortunately).  Is there a class pattern where you're allowed to
have more than one, but everything sucks when you do?  :^)

-=Eric


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

Date: Mon, 17 May 1999 15:06:37 -0700
From: lr@hpl.hp.com (Larry Rosler)
Subject: Re: Newbie: Aligning Text in Output File
Message-Id: <MPG.11aa32cc213f355f989a87@nntp.hpl.hp.com>

In article <7hpu21$k3a$1@news7.svr.pol.co.uk> on Mon, 17 May 1999 
21:24:37 +0100, Mug-O-Milk <webmaster@*nospam*mugomilk.freeserve.co.uk> 
says...
> I'm outputting IP addresses, dates and search criteria to a file (address
> below)
> http://mugomilk.hypermart.net/cgi-bin/search.txt

A few lines of data from that file:

Sun-16/4/99	193.237.214.229	17:36	sex	(3 Pages Found)
Sun-16/4/99	205.188.209.136	20:4		(0 Pages Found)
Mon-17/4/99	194.25.11.101	2:45	CCTV	(0 Pages Found)
Mon-17/4/99	194.238.50.7	8:0		(0 Pages Found)
Mon-17/4/99	204.96.33.222	8:50	cgi	(3 Pages Found)

Though you didn't ask -- you are misusing the output of 
(gm|local)time().  The month is zero-based, so you should add 1; the 
year is biased relative to 1900, so unless you have done something about 
that, soon you will be printing:

Sat-1/1/100

If you are interested in fixed widths for these fields and for the time 
fields, look into s?printf(), which lets you specify zero-padded 
numerical fields.

> I can do it in Java, but what is the code that I could use to align the last
> two columns (Search Words and Pages Found) without using TABs (\t), as there
> is not a maximum length (or an average) amount of words / characters that
> people can search for.

s?printf() also lets you specify fixed-length space-padded strings, 
left- or right-aligned.

I would suggest printing the Pages Found field first (with the integer 
space-padded appropriately), then printing the Search field last wihout 
padding, because you don't know or care how long it will be.
 
> And, Second Question, What code would I need to extract a RANDOM 10
> Questions (or Searches) (The Scalar is Named  - $question) from the
> datafile?  - As what Ask Jeeves does when you can "view" what others are
> searching for.

General guidleine for the future:  two questions, two posts, two 
Subjects.  And don't put 'Newbie' in the Subject, because some readers 
may filter it out, automatically or manually.

I am guessing at what you mean here, in particular what the scalar 
'$question' means.  You can split particular fields out of the data any 
way you wish.

Start with perlfaq4:  "How do I select a random element from an array?"  
To select a set of random elements, splice() each one out of the array 
(or a copy of the array that you don't mind destroying) before selecting 
the next one.

Here is a short version of what you may prefer at first to write as a 
loop (but learn to use map(); then you will no longer be a newbie).

    #!/usr/bin/perl -w
    use strict;
    
    my @array = ('a' .. 'z');
    my $max = @array < 10 ? @array : 10;
    my @selected = @array;
    @selected = map splice(@selected, rand @selected, 1), 1 .. $max;
    print "@selected\n";

-- 
(Just Another Larry) Rosler
Hewlett-Packard Company
http://www.hpl.hp.com/personal/Larry_Rosler/
lr@hpl.hp.com


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

Date: Mon, 17 May 1999 15:29:26 -0700
From: David Cassell <cassell@mail.cor.epa.gov>
Subject: Re: Newbie: Aligning Text in Output File
Message-Id: <37409846.E5E7292C@mail.cor.epa.gov>

Mug-O-Milk wrote:
> 
> I'm outputting IP addresses, dates and search criteria to a file (address
> below)
> http://mugomilk.hypermart.net/cgi-bin/search.txt

I took a look, and I have a suggestion below.  But Mug (if I
may speak to you informally), you're an experienced enough
netizen to know not to put the word 'newbie' in your subject
line.  That will at a minimum get you a lowered score for those
gurus in this ng who use slrn as their newsreader.  It will get
your post killed by other readers' newsreaders.
 
> I can do it in Java, but what is the code that I could use to align the last
> two columns (Search Words and Pages Found) without using TABs (\t), as there
> is not a maximum length (or an average) amount of words / characters that
> people can search for.

Perhaps surprisingly close to what you would have guessed.
Since you have an implicit limit on page width, I would suggest
printing out your $searchwords variable (or whatever you call it)
using (s)printf and left-justifying the text, padding on the
right with enough spaces that your $pagesfound variable gets
printed where you want.  This will also let you chop off the
right-hand end of $searchword values that are too long.
 
> And, Second Question, What code would I need to extract a RANDOM 10
> Questions (or Searches) (The Scalar is Named  - $question) from the
> datafile?  - As what Ask Jeeves does when you can "view" what others are
> searching for.

Do you want sampling without replacement?  Or do you want
sampling with replacement, and then checking to see whether 
the latest draw matches previous ones?  There is some code
for a single random value if you look in the FAQ.

David
-- 
David Cassell, OAO                     cassell@mail.cor.epa.gov
Senior computing specialist
mathematical statistician


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

Date: Mon, 17 May 1999 15:53:42 -0700
From: Josh Blackwell <josh@netoutfit.com>
To: <comp.lang.perl.misc@list.deja.com>
Subject: Re: Off-topic: France (was Re: Perl "constructors")
Message-Id: <87525971.926978492884.JavaMail.vpmail@ivpm2.dejanews.com>

At 5/14/99 - 01:55 PM, Ala Qumsieh wrote:
>
>Scratchie <upsetter@ziplink.net> writes:
>
>> I once went to France with an (American) friend who couldn't understand
>> why supermarkets sold bread in plastic bags that had little holes in them.
>> "It would stay fresh a lot longer if they'd use a regular bag", he
>> lamented.
>
>I hope I am not being stupid here, but why do the bags have little
>holes in them?


The French? Duh... so they can later store frogs in them.

-j


>
>
>
>
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
j o s h  j.  b l a c k w e l l                 josh@netoutfit.com
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Internet Outfitters, Inc.  310.664.4800  http://www.netoutfit.com




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

Date: 17 May 1999 23:40:14 GMT
From: damian@cs.monash.edu.au (Damian Conway)
Subject: Re: OOP and Perl-a good book?
Message-Id: <7hq9cu$e3e$1@towncrier.cc.monash.edu.au>

"%GIVEN NAME% o'regan" <"%GIVEN NAME%.o'regan"@port.ac.uk> writes:

>Would any be able recommend a good book that addresses OO in Perl
>comprehensively?

I have written such a book. It will be published by Manning
Publications in August this year. See http://www.manning.com/Conway/.

Not much help right now, I realize :-)

Damian


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

Date: Mon, 17 May 1999 23:54:42 GMT
From: dana@oz.net
Subject: Re: Parsing a data file...
Message-Id: <6%103.168$Ie1.11967@news14.ispnews.com>

In comp.lang.perl news.pacbell.net <beamanj@webvision.com> wrote:

npn: each line is intended to be a record, so I need to search through the
npn: records until I meet search criteria, like:
npn: 
npn: while not eof,
npn:     if value3=something then
npn:         do something
npn:         exit loop
npn:     endif
npn:     next record
npn: end while

You could do something like:


open (F, "data.file");
while ( <F> ) {
	@words = split / /, $_;
	$words[2] now contains the value you're looking for;
}


Does this help?


-- 

------------------------
Dana Booth <dana@oz.net>
Tacoma, Wa., USA
------------------------



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

Date: Mon, 17 May 1999 17:19:06 -0400
From: Ala Qumsieh <aqumsieh@matrox.com>
Subject: Re: Passing references
Message-Id: <x3yemkftmwm.fsf@tigre.matrox.com>


Briggs Reschke <briggs@texas.net> writes:

> I am trying to do something like, in C, passing a pointer to an array of
> structures to a subroutine and I'm getting nowhere.  The docs that I've
> come across are just confusing me more. 

What kind of help are you exactly looking for? Show us some code that
confuses you, and we'll be happy to clarify things for you.
You should also have a look at the 'perlref' and 'perlsub' docs.

HTH,
Ala



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

Date: 17 May 1999 23:11:37 GMT
From: ada@fc.hp.com (Andrew Allen)
Subject: Re: PERLFUNC: opendir - open a directory
Message-Id: <7hq7n9$aeo$2@fcnews.fc.hp.com>

Tom Christiansen (perlfaq-suggestions@perl.com) wrote:
: DIRHANDLEs have their own namespace separate from
:     FILEHANDLEs.

This sentence has always made me curious: how would I implement a
class of variables in my own "namespace"? Can it be done from pure
perl? *myvar{FOO}=\$a; gives a syntax error.

Also, is there a *myvar{THING} syntax to access dirhandles?

Andrew


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

Date: Mon, 17 May 1999 17:31:24 -0400
From: Ala Qumsieh <aqumsieh@matrox.com>
Subject: Re: regexp problem
Message-Id: <x3yd7zztmc3.fsf@tigre.matrox.com>


Mile Andric <andricm@cs.pdx.edu> writes:

> I have a string of words that might have an apostrophe (') in them.
> However, I just need to extract words that have one or more consonants
> in the beginning of the word and that don't have apostrophe in the body
> of the word.

something like that should work.

	/\b([^aeiou ']+(?!')\S+)/

If you require that the first letter be a consonant (the regexp above
will match anything not a vowel, a space or an apostrophe), then you
can change that to:

	/\b([b-df-hj-np-tv-z]+(?!')\S+)/

HTH,
Ala



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

Date: Mon, 17 May 1999 23:19:15 GMT
From: lou@visca.com
Subject: Using split with map, then join
Message-Id: <7hq85h$78f$1@nnrp1.deja.com>

I'm trying to use map to select certain fields from a bar-separated flat
file database and thus produce a smaller flat file database. After
splitting, when I put the bars back in using join, I have to do a rather
clumsy little substitution. I would be grateful if someone could suggest
a better way. Here's a sample of the database:

#1001|NRFB|820|Barbie in Mexico|NRFB|1|$250|A|02/19/99
#1002|NRFB|785|Dreamboat|NRFB|1|$80|A|02/19/99
#1004|NRFB|778|Ken in Mexico|NRFB|1|$175|A|02/19/99

And here's the script:

#!/usr/local/bin/perl

use strict;
use diagnostics;

my $data = 'database3.txt';

open DAT, $data or die $!;
my @data = <DAT>;
close DAT or die $!;

my @newdata = map {(split /\|/)[0,3..6], "\n"} @data;
my $new = join '|', @newdata;
$new =~ s/\|\n\|?/\n/g;

print $new;
----------
prints:
#1001|Barbie in Mexico|NRFB|1|$250
#1002|Dreamboat|NRFB|1|$80
#1004|Ken in Mexico|NRFB|1|$175

Thanks.
Lou Hevly
lou@visca.com


--== Sent via Deja.com http://www.deja.com/ ==--
---Share what you know. Learn what you don't.---


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

Date: Mon, 17 May 1999 23:37:01 GMT
From: Eric Bohlman <ebohlman@netcom.com>
Subject: Re: Using split with map, then join
Message-Id: <ebohlmanFBwHLp.GEv@netcom.com>

lou@visca.com wrote:
: I'm trying to use map to select certain fields from a bar-separated flat
: file database and thus produce a smaller flat file database. After
: splitting, when I put the bars back in using join, I have to do a rather
: clumsy little substitution. I would be grateful if someone could suggest
: a better way. Here's a sample of the database:

: #1001|NRFB|820|Barbie in Mexico|NRFB|1|$250|A|02/19/99
: #1002|NRFB|785|Dreamboat|NRFB|1|$80|A|02/19/99
: #1004|NRFB|778|Ken in Mexico|NRFB|1|$175|A|02/19/99

The last field on each line ends with a \n.

: And here's the script:

: #!/usr/local/bin/perl

You want a -w there.

: use strict;
: use diagnostics;

: my $data = 'database3.txt';

: open DAT, $data or die $!;
: my @data = <DAT>;
: close DAT or die $!;

: my @newdata = map {(split /\|/)[0,3..6], "\n"} @data;

You've already got a \n at the end of field 6, you don't need to add a 
new one.

my @newdata=(split /\|/)[0,3..6];

is all you need.

: my $new = join '|', @newdata;
: $new =~ s/\|\n\|?/\n/g;

You can drop this line, which removes the extra newline you added in.

: print $new;


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

Date: 12 Dec 98 21:33:47 GMT (Last modified)
From: Perl-Request@ruby.oce.orst.edu (Perl-Users-Digest Admin) 
Subject: Special: Digest Administrivia (Last modified: 12 Dec 98)
Message-Id: <null>


Administrivia:

Well, after 6 months, here's the answer to the quiz: what do we do about
comp.lang.perl.moderated. Answer: nothing. 

]From: Russ Allbery <rra@stanford.edu>
]Date: 21 Sep 1998 19:53:43 -0700
]Subject: comp.lang.perl.moderated available via e-mail
]
]It is possible to subscribe to comp.lang.perl.moderated as a mailing list.
]To do so, send mail to majordomo@eyrie.org with "subscribe clpm" in the
]body.  Majordomo will then send you instructions on how to confirm your
]subscription.  This is provided as a general service for those people who
]cannot receive the newsgroup for whatever reason or who just prefer to
]receive messages via e-mail.

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

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