[11701] in Perl-Users-Digest

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

Perl-Users Digest, Issue: 5301 Volume: 8

daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Mon Apr 5 15:06:25 1999

Date: Mon, 5 Apr 99 12:00:26 -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, 5 Apr 1999     Volume: 8 Number: 5301

Today's topics:
    Re: (newbie) matching value from array??? (Jerry)
        [Q] Help Needed on map (Effie Rover)
    Re: Counting spaces in a variable <cassell@mail.cor.epa.gov>
    Re: Does anyone know whats wrong with my script? (Larry Rosler)
    Re: Dump All Variables? (Tad McClellan)
        general module question <stevenhenderson@prodigy.net>
    Re: greping an associative array (Bill Moseley)
        Help for grep... <jearanai@my-dejanews.com>
    Re: How do i use the / character in split command. <cassell@mail.cor.epa.gov>
    Re: how to call java within perl (Abigail)
    Re: How to print n times a character? (Abigail)
        HTTP document transfers <infomage@infomage.force9.co.uk>
    Re: HTTP document transfers (Alastair)
    Re: HTTP document transfers <infomage@infomage.force9.co.uk>
        lc and future reserved word? <grichard@uci.edu>
    Re: lc and future reserved word? <uri@home.sysarch.com>
    Re: lc and future reserved word? (Larry Rosler)
    Re: No Echo over TCP Server <wells@cedarnet.org>
        Pick one of two files <nospam@nomail.com>
    Re: Pick one of two files <jglascoe@giss.nasa.gov>
        ppp connection with Perl igor1957@my-dejanews.com
    Re: ppp connection with Perl (I R A Aggie)
        PREL Beginner Questions... <c6635500@comp.polyu.edu.hk>
    Re: PREL Beginner Questions... (Tramm Hudson)
    Re: Premature end of script headers <infomage@infomage.force9.co.uk>
    Re: printing in foreach (Abigail)
    Re: Problem parsing Email Address (Tad McClellan)
        Retrieving dynamic frame content with LWP? <sthomas@carolina.rr.com>
    Re: Sending a email using PERL <tbc@col.hp.com>
    Re: Speed of PERL <jglascoe@giss.nasa.gov>
        splice incompatible with foreach <mdudley@execonn.com>
    Re: splice incompatible with foreach <jglascoe@giss.nasa.gov>
    Re: Tk.pm not installing properly on NT <rkoehler@osmre.gov>
    Re: Total beginner question (Abigail)
    Re: Trimming a number to only 2 decimal places (Abigail)
    Re: Trimming a number to only 2 decimal places <stevenhenderson@prodigy.net>
    Re: Trimming a number to only 2 decimal places <cassell@mail.cor.epa.gov>
        Unpack Question <jhisson1@columbus.rr.com>
    Re: Unpack Question (Greg Bacon)
    Re: Unpack Question <jhisson1@columbus.rr.com>
        Using Perl For ErrorDocuments (Tyler Hutcheon)
    Re: Very large regular expressions (Sean McAfee)
        Special: Digest Administrivia (Last modified: 12 Dec 98 (Perl-Users-Digest Admin)

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

Date: Mon, 05 Apr 1999 15:54:19 GMT
From: preeper@cts.com (Jerry)
Subject: Re: (newbie) matching value from array???
Message-Id: <3708dbb5.30226313@news2.cts.com>

I think I'm getting a little closer, but not quite there yet.
Assuming my variables that I want to match are $home and $away in the
loop that prints the results (this part works fine).  Now I add the
new query to get the urls from the teams table - this is added before
the loop printing these results, since I'm pretty sure I will only
need to do this query once and then keep reusing the data throughout
the loop.  The query to get the team names and url's is:

  $sql_query = "select city,short_name,full_name,url_link ";
  $sql_query .= "from $linktable";
  $sql_result = $dbh->Query($sql_query);
  while (@keys = $sql_result->FetchRow()) {
    $link_city = $keys[0];
    $link_short_name = $keys[1];
    $link_full_name = $keys[2];
    $url_link = $keys[3];
    }

I followed this with a sql query to get a count of the number of teams
in this league, like this:

  $sql_query = "select count(*) from $linktable";
  $sql_result = $dbh->Query($sql_query);
  while (@row = $sql_result->FetchRow()) {
  $team_count = $row[0];
  }

Now right after I start the loop to fetch each row of game scores and
assign all the data items in the row to a variable name, I have added:

      for $i (0 .. $team_count) {
      if ($link_city{$i} == $away) {
        $away_link = $url_link{$i};
     } else {$i++}
     }
     }

But it doesn't ever seem to match and nothing ever gets printed for
the link.

Jerry




>Larry Rosler <lr@hpl.hp.com> wrote:
>
>> In article <qc18e7.g1p.ln@magna.metronet.com> on Sun, 4 Apr 1999 
>> 11:44:26 -0400, Tad McClellan <tadmc@metronet.com> says...
>> > Jerry (preeper@cts.com) wrote:
>> ...
>> > :   $sql_query = "select city,short_name,full_name,url_link ";
>> > :   $sql_query .= "from $linktable";
>> > :   $sql_result = $dbh->Query($sql_query);
>> > :   while (@row = $sql_result->FetchRow()) {
>> > :     $link_city = $row[0];
>> > :     $link_short_name = $row[1];
>> > :     $link_full_name = $row[2];
>> > :     $url_link = $row[3];
>> > :     }
>> > 
>> > 
>> >    That is a cumbersome way to load up your variables.
>> > 
>> >    You can shorten the body of the while loop to a single line:
>> > 
>> >       ($link_city, $link_short_name, $link_full_name, $url_link) = @row;
>> 
>> Which overwrites those variables each time through the loop, so their
>> values on loop exit are those of the last iteration.  That *may* be what
>> is wanted, but I doubt it.
>
>Well, it's no different from what the original code did, anyway...
>I'd guess that the original poster is asking for code that will complete
>the body of that while loop.  I didn't have any better luck than Tad at
>understanding the question, though.
>
>
>-- 
> _ / '  _      /       - aka -
>( /)//)//)(//)/(   Ronald J Kimball      rjk@linguist.dartmouth.edu
>    /                                http://www.tiac.net/users/chipmunk/
>        "It's funny 'cause it's true ... and vice versa."



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

Date: Mon, 05 Apr 1999 18:28:27 GMT
From: null@effierover.com (Effie Rover)
Subject: [Q] Help Needed on map
Message-Id: <37090004.14111298@news.iinc.com>


I've looked at my Perl books and at some examples online, and can't
seem to get my head around the map function.  I have a feeling I could
make my search engine more efficient with this, but can't even
understand what's going on in FAQ 6.16...
@poppats   = map { qr/\b$_\b/i } @popstates;

Can anyone point out some good examples of useful code using map WITH
explanations? Either on web tutorials or posted here ... that's how I
learn best. Thanks!

  -- Loy

Loy Ellen Gross AKA Effie Rover
The email address above goes straight to /dev/null :-)
effie -at- effierover -dot- com * http://www.effierover.com
Effie Rover's Fantasy Role Playing Gamer's Library
---------------------------------------------------------------
Protect privacy, boycott Intel: http://www.bigbrotherinside.org
---------------------------------------------------------------


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

Date: Mon, 05 Apr 1999 11:30:58 -0700
From: "David L. Cassell" <cassell@mail.cor.epa.gov>
Subject: Re: Counting spaces in a variable
Message-Id: <37090162.80F2794E@mail.cor.epa.gov>

Frank de Bot wrote:
> I think this should work:
> my $count = () = $string =~ /\s/g
> 
> "IndexFinger.com" wrote:
> > What is the function to count the number of spaces in a variable?
> > Example: "This is an example variable"
> > In the example, there are 4 spaces.

Errm.. that doesn't work.  Sorry.  \s picks up *all* whitespace,
including tabs and newlines too.  Second, there is a better,
faster way to do this.. and it's in the FAQ.  tr/// is great for
this sort of problem.

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


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

Date: Mon, 5 Apr 1999 11:43:24 -0700
From: lr@hpl.hp.com (Larry Rosler)
Subject: Re: Does anyone know whats wrong with my script?
Message-Id: <MPG.1172a424740f309a989830@nntp.hpl.hp.com>

[Posted and a courtesy copy mailed.]

In article <MPG.117269ad8c19e54198970a@206.184.139.132> on Mon, 5 Apr 
1999 07:33:59 -0700, Bill Moseley <moseley@best.com> says...
 ...
> Passing in a single variable I'd use
> 
> $Onlydate = $_;

I wouldn't use that, as it has nothing to do with passing variables into 
subroutines.  I'd use

  $Onlydate = $_[0];

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


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

Date: Mon, 5 Apr 1999 07:31:03 -0400
From: tadmc@metronet.com (Tad McClellan)
Subject: Re: Dump All Variables?
Message-Id: <nt6ae7.apu.ln@magna.metronet.com>

Shari Callaghan (revjack@radix.net) wrote:
: Zenin explains it all:
: :Turin Waterbury <revjack@radix.net> wrote:
: :: Is there an elegant way to get perl to somehow report the values of
: :: *all* variables in memory, including vars like $$, $_, $|, and variables
: :: created by the script, like $foo etc?

: :	See the "V" and "X" commands of the debugger (perldoc perldebug). 
: :	Infact, see the debugger in general.

: I was hoping to avoid the debugger. Any other way?


   You can poke around in the Symbol Table for dynamic variables.
   (See the "Symbol Tables" section in perlmod.pod)

   I dunno how to get to lexical variables outside of the debugger
   without knowing their names.


--
    Tad McClellan                          SGML Consulting
    tadmc@metronet.com                     Perl programming
    Fort Worth, Texas


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

Date: Mon, 5 Apr 1999 08:35:41 -0500
From: "Steven T. Henderson" <stevenhenderson@prodigy.net>
Subject: general module question
Message-Id: <jN4O2.20959$oa3.200359@news.san.rr.com>

currently, when my perl program is executed, i am passed a series of values
that correspond to form fields in an *existing* HTML file. i parse in this
file, substitute the passed values for any defaults and display the form.
this 'dynamic defaulting' allows me to edit existing records in a form-entry
database. additionaly, by using an existing HTML file (my form), i can let
my designer dink with colors, graphics, etc. w/o affecting me.

my question is: is there an existing PM or library that does all this work
for me? what is the standard way of performing this action? i know this is
done elsewhere, but cannot find it any faq's or posts.





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

Date: Mon, 5 Apr 1999 08:00:42 -0700
From: moseley@best.com (Bill Moseley)
Subject: Re: greping an associative array
Message-Id: <MPG.11726ff8a2eeb3c498970c@206.184.139.132>

In article <3708C8DB.F2E1EF6A@nacs.net>, rocket@nacs.net says...
> I am new to perl, and programing for that matter, what I am trying to
> figure out is if you can grep an associative array same as a standard
> array as in grep(/$var/, @array); works, grep(/$var/, %array); does
> not.

What are you trying to do?  They both work for me, but I'd bet 
grep(/$var/, %array) isn't doing what you want.



  Also I am having trouble loading an open file into an associative
> array,
>     open(FILE,  myfile);
>     @array = <FILE>;   works
> 
>     open(FILE, myfile);
>      %array =  <FILE>; doesn't, what am I missing? If someone could

Well, that last one would depend on the format of your file, I suppose.  
You file would have to look like:

key1
value1
key2
value2

Which I doubt.


What does your data look like?  And what are you trying to do?

-- 
Bill Moseley mailto:moseley@best.com


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

Date: Mon, 05 Apr 1999 18:01:22 GMT
From: apple <jearanai@my-dejanews.com>
Subject: Help for grep...
Message-Id: <7eatpd$3tn$1@nnrp1.dejanews.com>

I would like to grep a word ->
myname
from a line ->
<test>myname</test>

after I read this line to my perl file. How can I grep it as a $name=myname.

Help me ,please...

apple

-----------== Posted via Deja News, The Discussion Network ==----------
http://www.dejanews.com/       Search, Read, Discuss, or Start Your Own    


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

Date: Mon, 05 Apr 1999 11:47:27 -0700
From: "David L. Cassell" <cassell@mail.cor.epa.gov>
Subject: Re: How do i use the / character in split command.
Message-Id: <3709053F.CEA1FD4B@mail.cor.epa.gov>

agniora@usa.net wrote:
> In the split command how will i use the / character.
> eg
> to split the string
> 
> $t = '21/03/99';
> @t=split (/\//,$t);
> 
> this doesnt work.

It should.  What happens elsewhere in your code that might be
making this appear to fail?  Did you get any warnings from the
-w flag or the 'use strict' pragma?

See if you can write a very small but complete prog which
illustrates your problem, and then post that.  It will be 
easier to help you find the problem.

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


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

Date: 5 Apr 1999 15:00:31 GMT
From: abigail@fnx.com (Abigail)
Subject: Re: how to call java within perl
Message-Id: <7eaj6f$jek$4@client2.news.psi.net>

Hailan Wang (wangh@cs.purdue.edu) wrote on MMXLI September MCMXCIII in
<URL:news:7e5ubq$bjo$1@mozo.cc.purdue.edu>:
'' I am working on a web project, and I need to
'' call some java functions inside perl because
'' I want to use perl as my main web data carrier
'' but I want to use java to deal with the data processing
'' on the server. So is there a way to do this? Another
'' word, is it possible for a perl script to call java  application
'' at the server (not java applet)? Please help and thanks a lot.


Perl has various ways of calling an external program: system(), open(),
qx(), and exec(). Perl doesn't care whether the external program is
written in Perl, C, PASCAL, Intercal, Java or something else.



Abigail
-- 
srand 123456;$-=rand$_--=>@[[$-,$_]=@[[$_,$-]for(reverse+1..(@[=split
//=>"IGrACVGQ\x02GJCWVhP\x02PL\x02jNMP"));print+(map{$_^q^"^}@[),"\n"


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

Date: 5 Apr 1999 15:01:39 GMT
From: abigail@fnx.com (Abigail)
Subject: Re: How to print n times a character?
Message-Id: <7eaj8j$jek$5@client2.news.psi.net>

Federico Abascal (fabascal@gredos.cnb.uam.es) wrote on MMXLIII September
MCMXCIII in <URL:news:3708978B.51DB4126@gredos.cnb.uam.es>:
&& Please I don't remember how to do it and where I saw how it has to be
&& done?


    print "n times a character";


Or perhaps you want:

    print 'c' x $n;


Abigail
-- 
srand 123456;$-=rand$_--=>@[[$-,$_]=@[[$_,$-]for(reverse+1..(@[=split
//=>"IGrACVGQ\x02GJCWVhP\x02PL\x02jNMP"));print+(map{$_^q^"^}@[),"\n"


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

Date: Mon, 05 Apr 1999 18:43:57 +0100
From: Infomage <infomage@infomage.force9.co.uk>
Subject: HTTP document transfers
Message-Id: <3708F65D.648EE49E@infomage.force9.co.uk>

Hi.

I am a novice, so please be gentle.  I was hoping that someone in this
NG would be able to point me in the right direction for an *easily*
configured script for accessing a remote HTML document via HTTP.

I have taught myself what little PERL I know from a book, and have
managed to write a script that will do all I want *if* I can get the
remote file.

Hope you can help.

:o)


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

Date: Mon, 05 Apr 1999 17:53:04 GMT
From: alastair@calliope.demon.co.uk (Alastair)
Subject: Re: HTTP document transfers
Message-Id: <slrn7gi1ks.5v.alastair@calliope.demon.co.uk>

Infomage <infomage@infomage.force9.co.uk> wrote:
>Hi.
>
>I am a novice, so please be gentle.  I was hoping that someone in this
>NG would be able to point me in the right direction for an *easily*
>configured script for accessing a remote HTML document via HTTP.

Use the libwww module e.g.

use LWP::Simple;
$doc = get 'http://www.sn.no/libwww-perl/';

The above is straight from the docs ('lwpcook').

HTH.

-- 

Alastair
work  : alastair@psoft.co.uk
home  : alastair@calliope.demon.co.uk


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

Date: Mon, 05 Apr 1999 19:17:53 +0100
From: Infomage <infomage@infomage.force9.co.uk>
Subject: Re: HTTP document transfers
Message-Id: <3708FE51.56C4C6EC@infomage.force9.co.uk>




> Use the libwww module e.g.
> 
> use LWP::Simple;
> $doc = get 'http://www.sn.no/libwww-perl/';
> 
> The above is straight from the docs ('lwpcook').
> 
> HTH.
> 

OK...  Have tried that in many guises...  The problem I am getting is
that I need to use an intermediate variable as the actual URL will
potentially be different each time the script runs.

As it is, I just get an empty return from the 'get' command, and then
when I run using the -w flag, I get messages complaining of an undefined
variable.  (The one that *should* be filled with the output from the
'get')

<Pulling out hair>     ...      </Pulling out hair>

:o)


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

Date: Mon, 5 Apr 1999 10:49:38 -0700
From: "Gabriel Richards" <grichard@uci.edu>
Subject: lc and future reserved word?
Message-Id: <7easta$81d@news.service.uci.edu>

Here's the error message sprouted from perl -w:

-----
"lc" may clash with future reserved word at listings.cgi line 23.
syntax error in file listings.cgi at line 23, next 2 tokens "lc $input"
syntax error in file listings.cgi at line 49, next token "}"
syntax error in file listings.cgi at line 55, next token "}"
Execution of listings.cgi aborted due to compilation errors.
----

Here's the code:

----
 $type = lc $input{'type'};
----
My program works as expected without this line. But I try to lowercase the
user's input and kaput. I'm new...and I don't understand. The camel book
seems to indicate that this is the correct syntax.

Gabe





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

Date: 05 Apr 1999 14:00:48 -0400
From: Uri Guttman <uri@home.sysarch.com>
Subject: Re: lc and future reserved word?
Message-Id: <x7r9pzueun.fsf@home.sysarch.com>

>>>>> "GR" == Gabriel Richards <grichard@uci.edu> writes:

  GR> "lc" may clash with future reserved word at listings.cgi line 23.

  GR>  $type = lc $input{'type'};


sounds like you are using a rotten camel carcass. lc is new to perl5 and
you are probably using perl4. run perl -v to verify,

uri

-- 
Uri Guttman  -----------------  SYStems ARCHitecture and Software Engineering
uri@sysarch.com  ---------------------------  Perl, Internet, UNIX Consulting
Have Perl, Will Travel  -----------------------------  http://www.sysarch.com
The Best Search Engine on the Net -------------  http://www.northernlight.com


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

Date: Mon, 5 Apr 1999 11:52:06 -0700
From: lr@hpl.hp.com (Larry Rosler)
Subject: Re: lc and future reserved word?
Message-Id: <MPG.1172a62e63b1277d989831@nntp.hpl.hp.com>

[Posted and a courtesy copy mailed.]

In article <7easta$81d@news.service.uci.edu> on Mon, 5 Apr 1999 10:49:38 
-0700, Gabriel Richards <grichard@uci.edu> says...
> "lc" may clash with future reserved word at listings.cgi line 23.
> syntax error in file listings.cgi at line 23, next 2 tokens "lc $input"
> syntax error in file listings.cgi at line 49, next token "}"
> syntax error in file listings.cgi at line 55, next token "}"
> Execution of listings.cgi aborted due to compilation errors.
> ----
>  $type = lc $input{'type'};
> ----
> My program works as expected without this line. But I try to lowercase the
> user's input and kaput. I'm new...and I don't understand. The camel book
> seems to indicate that this is the correct syntax.

Apparently you are using Perl 4.  Try `perl -v` to be sure.

Install Perl 5 and all should be well. 

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


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

Date: Mon, 05 Apr 1999 15:16:38 +0000
From: Steve Wells <wells@cedarnet.org>
Subject: Re: No Echo over TCP Server
Message-Id: <3708D3D6.DE48E6B6@cedarnet.org>

Steve Wells wrote:
> 
> I have a server that I want people to enter a password
> at and not have it echo back to their terminal.
> 
> Here's the relevant section of code:
> ---------------------------------------
> use IO::Socket;
> use Term::ReadKey;
> 
> my $server = IO::Socket::INET->new(LocalPort => $server_port,
>                                    Type      => SOCK_STREAM,
>                                    Reuse     => 1,
>                                    Listen    => 10)
>           or die "Couldn't be a tcp server on $server_port";
> 
> while (my $client = $server->accept()) {
>        print $client "Password: ";
>        ReadMode('noecho', $client);
>        chomp(my $password = ReadLine(0, $client));
>        print "PASSWORD: $password\n";
> }
> -------------------------------------------
> 
> Questions:
> 1) WHY doesn't this work?
> 
> 2) WHAT will work?

It seems that is does work if you are using Windows
Telnet.  I'm using linux though and everything is
echoing....

Any ideas?

TIA,
STEVE
-- 
-----------
Stephen D. Wells
http://www.iren.net/wellss/


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

Date: Mon, 05 Apr 1999 15:30:30 GMT
From: "Scribbles" <nospam@nomail.com>
Subject: Pick one of two files
Message-Id: <qG4O2.349$qe1.572@c01read04.service.talkway.com>

Hiyas,

This is probably pretty basic; can I have an <A HREF> point to a cgi
script that will display one file if it exists, another if it doesn't,
and if so, any examples anywhere around? TIA.
--
Posted via Talkway - http://www.talkway.com
Surf Usenet at home, on the road, and by email -- always at Talkway.



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

Date: Mon, 05 Apr 1999 14:40:05 -0400
From: Jay Glascoe <jglascoe@giss.nasa.gov>
To: Scribbles <nospam@nomail.com>
Subject: Re: Pick one of two files
Message-Id: <37090385.F2212BED@giss.nasa.gov>

Scribbles wrote:
> 
> Hiyas,
> 
> This is probably pretty basic; can I have an <A HREF> point to a cgi
> script that will display one file if it exists, another if it doesn't,
> and if so, any examples anywhere around? TIA.

my ($file) = grep { -e } qw(foo.html bar.html)
    or die "neither file exists: $!";
local *FH;
open FH, "< $file" or die "can't open file: $!";
print "Content-type: text/html\n\n";
print while <FH>;
	
	Jay Glascoe


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

Date: Mon, 05 Apr 1999 17:38:04 GMT
From: igor1957@my-dejanews.com
Subject: ppp connection with Perl
Message-Id: <7easdr$2i2$1@nnrp1.dejanews.com>

Hi,

Who knows how to write a perl program under Red Hat Linux to make
ppp-connection to my ppp-server. It also work under Linux.

Thank you in advance.

Igor.

-----------== Posted via Deja News, The Discussion Network ==----------
http://www.dejanews.com/       Search, Read, Discuss, or Start Your Own    


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

Date: 5 Apr 1999 18:26:09 GMT
From: fl_aggie@thepentagon.com (I R A Aggie)
Subject: Re: ppp connection with Perl
Message-Id: <slrn7gi06r.e3j.fl_aggie@stat.fsu.edu>

On Mon, 05 Apr 1999 17:38:04 GMT, igor1957@my-dejanews.com
<igor1957@my-dejanews.com> wrote:

+ Who knows how to write a perl program under Red Hat Linux to make
+ ppp-connection to my ppp-server. It also work under Linux.

Have you read the Linux PPP HOW-TO document? Why do you want to
re-invent the wheel? its already been done.

James

<url:http://metalab.unc.edu/mdw/HOWTO/PPP-HOWTO.html>
-or explore- 
<url:ftp://metalab.unc.edu/pub/Linux/docs/howto/other-formats/>
for other formats...


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

Date: Tue, 06 Apr 1999 01:13:54 -0700
From: Jimmy <c6635500@comp.polyu.edu.hk>
Subject: PREL Beginner Questions...
Message-Id: <3709C242.6DC8@comp.polyu.edu.hk>

Hello all,
	I am new to PERL. I have questions about using PERL.

1.	binmode(DBF);
2.	print DBF "\x03";
3. 	print DBF "\x0";
4.	print DBF pack('a20','');

	What the meaning of putting "\x03" "\x0" in line 2 and 3? What is the
meaning of using pack in line 4? Moroever, could anyone suggest good
books on PERL 5.0?

Thanks,
Jimmy


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

Date: 5 Apr 1999 12:28:34 -0600
From: hudson@swcp.com (Tramm Hudson)
Subject: Re: PREL Beginner Questions...
Message-Id: <7eavci$g39@llama.swcp.com>

[cc'd to cited author and clp.modules removed]

In article <3709C242.6DC8@comp.polyu.edu.hk>,
Jimmy  <c6635500@comp.polyu.edu.hk> wrote an article titled:
> Subject: Re: PREL Beginner Questions...

Just remember that the instructions for using Prell are:

	use Shampoo;
	rinse while lather or die "No more hot water: $!\n";

>1.	binmode(DBF);
>2.	print DBF "\x03";
>3. 	print DBF "\x0";
>4.	print DBF pack('a20','');

So I assume that you have opened a database file (and checked the 
return from open, right?).  You then switch it to binary mode just
in case you're running on a braindead platform that requires such
a distinction.  Then you write the binary string:

  03 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 

to the file.  The \x specifies a hex translation for the numeric value
following (see perldoc perlop).  Now what that string means is a mystery
to all of us out here with out any more details, but I posit that it
signals Bejing to launch the nuclear strike against your dorm room in
the former British colony of Hong Kong for engaging in imperial capatalist
practices.  Change the \x0 to \x1 and they will send you seven metric
tons of green tea instead while the missles are shot at Taiwan.

pack is rather difficult to explain in a single post.  You should
consult the perlfun page for info on how it works (perldoc -f pack),
where hundreds if not thousands of trained mammals have written
an excellent description of how it works.

>Moroever, could anyone suggest good books on PERL 5.0?

The included documentation is a good place to start for specific perl
questions (perldoc perltoq).  For more general help, you should have
a copy of the Llama book (_Learning Perl_).  A list of good perlbooks
is in the perlbook page.

Good luck with it.
Tramm
-- 
  o   hudson@swcp.com                 tbhudso@cs.sandia.gov   O___|   
 /|\  http://www.swcp.com/~hudson/          H 505.266.59.96   /\  \_  
 <<   KC5RNF @ N5YYF.NM.AMPR.ORG            W 505.284.24.32   \ \/\_\  
  0                                                            U \_  | 


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

Date: Mon, 05 Apr 1999 18:49:38 +0100
From: Infomage <infomage@infomage.force9.co.uk>
Subject: Re: Premature end of script headers
Message-Id: <3708F7B2.AED142FC@infomage.force9.co.uk>


<snip>

Just a little suggestion that you may or may not be aware of...

It is *essential* that when you upload your script, you send it in ASCII
mode rather than Binary.  This prevents the FTP process replacing
certain characters which are needed by PERL to interpret the script
correctly.

I have heard many people complaining of this problem, and when ASCII
protocol is used, the problem ceases.

:o)


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

Date: 5 Apr 1999 15:13:54 GMT
From: abigail@fnx.com (Abigail)
Subject: Re: printing in foreach
Message-Id: <7eajvi$jek$6@client2.news.psi.net>

Wayne Collins (collinw@netinc.ca) wrote on MMXLI September MCMXCIII in
<URL:news:370667F6.8A50FC6D@netinc.ca>:
== The code below prints . . .
== 5
== 4
== 3
== 2
== 1
== BOOM!
== . . . with a 1 second pause after each item.
== foreach $count (5, 4, 3, 2, 1, 'BOOM!')
== {
==     print $count, "\n";
==     sleep (1);
== }
== 
== If I change the code to this . . .
== foreach $count (5, 4, 3, 2, 1, 'BOOM!')
== {
==     print $count;
==     sleep (1);
== }
== print "\n";
== There is a six second pause and then the entire line is printed. It
== appears the newline character is required to get something to the
== screen. Can anyone explain that? Merci.


Buffering.



Abigail
-- 
perl -we 'print split /(?=(.*))/s => "Just another Perl Hacker\n";'


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

Date: Mon, 5 Apr 1999 07:23:48 -0400
From: tadmc@metronet.com (Tad McClellan)
Subject: Re: Problem parsing Email Address
Message-Id: <4g6ae7.apu.ln@magna.metronet.com>

ryanm (ryanm@accn.org) wrote:

: How can I do the following:
: change <username@domain.net>... into just username??


   s/<([^@]+)@.*/$1/;


--
    Tad McClellan                          SGML Consulting
    tadmc@metronet.com                     Perl programming
    Fort Worth, Texas


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

Date: Mon, 05 Apr 1999 16:31:51 GMT
From: Scott Thomas <sthomas@carolina.rr.com>
Subject: Retrieving dynamic frame content with LWP?
Message-Id: <3708E5A4.9FCFB904@carolina.rr.com>

How can my script obtain (with permission) content of a single frame
(the page consists of 3 frames), generated from a database in response
to a form POST?

In other words, my script submits a POST to a specific asp script,
index.asp. The response generated is the index.asp page, consisting of 3
frames. Two of the frames are irrelevant to me. The third (named
search.asp) contains the results of my search.

If I post to index.asp, the result is the index.asp page, which shows
the <Frameset> tags and a <NoFrames> section. Unfortunately, the no
frames section is empty, and the site has refused to make it work
properly. When I POST my form data directly to search.asp, the resulting
page indicates that my request was empty.

Here is the code, more or less take from the LWP documentation (some
pasted-in material may also be here):

  use LWP::UserAgent;
  use HTTP::Request::Common qw(POST);
  use URI::URL;

  $url = "http://www.snipped-site.net/search/index.asp";

  my $req = POST "$url",
           [ county => "", last_name => "", search_type => 2, city => ""
];

  $ua = new LWP::UserAgent;
  $result = $ua->request($req)->as_string;

  open (OUT, ">output.txt");
  print OUT $result;
  close OUT;



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

Date: Mon, 5 Apr 1999 12:49:58 -0600
From: "Tim Chambers" <tbc@col.hp.com>
Subject: Re: Sending a email using PERL
Message-Id: <7eb0o9$ajn$1@nonews.col.hp.com>

>I am writing a script which requires sending a email to the web master.  I
>have tried the following script, without much luck.  I have pasted the FULL
>script, if you could be give me an ideas??


I went down the same path as you. Now I just

use Mail::Send;

<>< Tim

http://www.geocities.com/Athens/3680/ (Personal Web)
The opinions and URL recommendations stated here are my own
and do not necessarily represent those of Hewlett-Packard.





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

Date: Mon, 05 Apr 1999 14:24:50 -0400
From: Jay Glascoe <jglascoe@giss.nasa.gov>
To: Patrick Fichou <fichou@club-internet.fr>
Subject: Re: Speed of PERL
Message-Id: <3708FFF2.D2DBD304@giss.nasa.gov>

Patrick Fichou wrote:
> 
> I wrote a script that reads 8000 lines from a text file (ASCII) and update
> an Excel Sheet with the OLE module... But while it takes 2 minutes with
> Excel VBA it takes 20 minutes with a perl Script !

I seriously doubt that VB is quicker than Perl, assuming
your perl was compiled properly. Perhaps your Perl code
uses inefficient algorithms.  Are you passing large arrays
to and from subroutines?  Are you using references?  Are
your regexes efficient?

	Jay Glascoe


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

Date: Mon, 05 Apr 1999 14:03:00 -0400
From: Marshall Dudley <mdudley@execonn.com>
Subject: splice incompatible with foreach
Message-Id: <3708FAD3.7B815030@execonn.com>

I am trying to go through an array and do something with each element,
and in some cases remove the element from the array.  The splice
function is the only one I can find to let me do this, but it interacts
with the foreach so I get screwy results.

This simple script is suppose to look at all lines and remove those that
say remove.  But it completely misses any line after a remove, and
doesn't always remove the lines with remove in them.  Does anyone know
an easy solution to getting around this?

Thanks,

Marshall

@lines = ("1 keep","2 keep","3 remove","4 keep","5 remove","6 remove","7
keep");
$count = -1;
foreach $line (@lines) {
        $count++;
#do things with that particular $line here then remove some of the lines
from the array
        if ($line =~ /remove/) {splice (@lines,$count,1); }
        print "$line\n";
}
print "\n";
foreach $line (@lines) { print "$line\n"; }

RESULT:

1 keep
2 keep
3 remove
5 remove
7 keep

1 keep
2 keep
4 keep
6 remove
7 keep




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

Date: Mon, 05 Apr 1999 14:18:57 -0400
From: Jay Glascoe <jglascoe@giss.nasa.gov>
To: Marshall Dudley <mdudley@execonn.com>
Subject: Re: splice incompatible with foreach
Message-Id: <3708FE91.B7CDEB7A@giss.nasa.gov>

[courtesy copy of post sent to cited author]

Marshall Dudley wrote:
> 
> I am trying to go through an array and do something with each element,
> and in some cases remove the element from the array.  

<snip>

> Does anyone know
> an easy solution to getting around this?

why not create a new array?

> @lines = ("1 keep","2 keep","3 remove","4 keep","5 remove","6 remove","7
> keep");

# this is a functional solution:
my @keepers = grep { $_ !~ /remove/ } @lines;

# or, if you like
my @keepers = ();
foreach my $line (@lines) {
    do_something($line);
    push @keepers, $line unless $line =~ /remove/;
}

# this is more magical, but some may frown upon
# using side effects along with grep:
my @keepers = grep { do_something($_), $_ !~ /remove/ } @lines;

	Jay Glascoe


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

Date: Mon, 5 Apr 1999 16:49:53 GMT
From: "Rick K" <rkoehler@osmre.gov>
Subject: Re: Tk.pm not installing properly on NT
Message-Id: <F9q6qr.76E@igsrsparc2.er.usgs.gov>

John Call wrote:
>I am using Perl on NT (sigh.....) and am using PPM to install some modules.
>When I install Tk everything seems to install just fine but when I try to
>use Tk; I get an error.
>
>I looked at the Tk.pm file and it was empty and so were some of the other
>files that were downloaded into the Tk file structure.
>
>From what I read about PPM it is supposed to handle all of the installation,
>isn't it?
>
>The machine is running NT 4.0 with Service Pack 3. I am behind a firewall
[snipski ...]

The Tk module installs just fine on my NT machines; I've done it by hand, and
also used the VPM technique.  Here are some points to ponder:

a) Tk is a fairly large module, and takes quite a bit of time to download (if
    you're getting it that way; patience was in short supply for me;

b) I don't know how your firewall is configured; what kind of constraints
    exist on "incoming" data (from external source)?;

c) If you suspect a problem with the firewall, or PPM, maybe a test using a
    very small, "don't care" module would be in order; if the small install works,
    then, by extension, the larger should also, unless ...

d) Any problems with the server "timing-out" while you download something
    as large as the Tk module?

e)  All of this kinda predicated upon exactly what install of Perl you're using;
     what build, pre-compiled binary, roll-your-own, etc., ... where are your
     libs configured?

HTH, but it probably doesn't.  Good luck.





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

Date: 5 Apr 1999 15:18:12 GMT
From: abigail@fnx.com (Abigail)
Subject: Re: Total beginner question
Message-Id: <7eak7k$jek$7@client2.news.psi.net>

Cal Bond (cal@spacemoose.com) wrote on MMXLII September MCMXCIII in
<URL:news:3706E817.3522@spacemoose.com>:
@@ Hi-
@@ 
@@ I've been just trying to alter pre-made perl scripts to refernece files
@@ in my page etc, but it seems as soon as I open them up with a text
@@ editor and resave them with the same name (blah.pl, etc.) I get a 
@@ 'Premature end of script headers' error from my webpage using them. 
@@ I've just been using notepad to edit them - should I be using another
@@ text editor or am I just doing somehing really stupid?


Yes. You asked a non-Perl question in a Perl newsgroup.


Please step away from the keyboard, and go with the men dressed in
white uniforms. They'll bring you to a nice rubber padded room.



Abigail
-- 
perl -we '$@="\145\143\150\157\040\042\112\165\163\164\040\141\156\157\164".
             "\150\145\162\040\120\145\162\154\040\110\141\143\153\145\162".
             "\042\040\076\040\057\144\145\166\057\164\164\171";`$@`'


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

Date: 5 Apr 1999 15:19:34 GMT
From: abigail@fnx.com (Abigail)
Subject: Re: Trimming a number to only 2 decimal places
Message-Id: <7eaka6$jek$8@client2.news.psi.net>

hogringer@earthlink.net (hogringer@earthlink.net) wrote on MMXLII
September MCMXCIII in <URL:news:3709ea06.5727574@news.earthlink.net>:
// Can someone tell me how to trim a dollar amount to just 2 decimal
// places?  I want to print "Federal tax is $xxx.xx" and I get a number
// with 6-8 numbers to the right of the decimal.  I tried using %.2f but
// I must not be using it right because it wont display right.  I have a
// line  that reads
// 
// $ftax = ($gross*.10);
// 
// and then it is displayed with this line
// 
// print "         | Federal tax is \$$ftax
// 
// I would like to get rid of all the extra digits.  Can someone help me
// with this?  Thanks


I don't see any %.2f there.




Abigail
-- 
%0=map{reverse+chop,$_}ABC,ACB,BAC,BCA,CAB,CBA;$_=shift().AC;1while+s/(\d+)((.)
(.))/($0=$1-1)?"$0$3$0{$2}1$2$0$0{$2}$4":"$3 => $4\n"/xeg;print#Towers of Hanoi


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

Date: Mon, 5 Apr 1999 09:13:33 -0500
From: "Steven T. Henderson" <stevenhenderson@prodigy.net>
Subject: Re: Trimming a number to only 2 decimal places
Message-Id: <Pk5O2.20973$oa3.200687@news.san.rr.com>

yeah, other problems withstanding.... you can simply:


    # Treat identifier as a string to round up
    if($cost =~ /\./)
    {
        $cost++;
        $cost =~ s/\..*//;
    }




hogringer@earthlink.net wrote in message
<3709ea06.5727574@news.earthlink.net>...
>Can someone tell me how to trim a dollar amount to just 2 decimal
>places?  I want to print "Federal tax is $xxx.xx" and I get a number
>with 6-8 numbers to the right of the decimal.  I tried using %.2f but
>I must not be using it right because it wont display right.  I have a
>line  that reads
>
>$ftax = ($gross*.10);
>
>and then it is displayed with this line
>
>print "         | Federal tax is \$$ftax
>
>I would like to get rid of all the extra digits.  Can someone help me
>with this?  Thanks
>
>Gary
>




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

Date: Mon, 05 Apr 1999 11:42:48 -0700
From: "David L. Cassell" <cassell@mail.cor.epa.gov>
Subject: Re: Trimming a number to only 2 decimal places
Message-Id: <37090428.7F28FB7C@mail.cor.epa.gov>

Steven T. Henderson wrote:
> 
> yeah, other problems withstanding.... you can simply:
> 
>     # Treat identifier as a string to round up
>     if($cost =~ /\./)
>     {
>         $cost++;
>         $cost =~ s/\..*//;
>     }
> 
> hogringer@earthlink.net wrote in message
> <3709ea06.5727574@news.earthlink.net>...
> >Can someone tell me how to trim a dollar amount to just 2 decimal
> >places?  I want to print "Federal tax is $xxx.xx" and I get a number
> >with 6-8 numbers to the right of the decimal.  I tried using %.2f but
> >I must not be using it right because it wont display right.  I have a
> >line  that reads
> >
> >$ftax = ($gross*.10);
> >
> >and then it is displayed with this line
> >
> >print "         | Federal tax is \$$ftax
> >
> >I would like to get rid of all the extra digits.  Can someone help me
> >with this?  Thanks
> >
> >Gary
> >

Just a couple points. 
(1) Your solution doesn't answer his question.  It certainly
does not round off to 2 decimal places.
(2) This is not the optimal way to do rounding.  See the FAQ.
(3) This actually doesn't *round* anything.  It is 'sort of' a
ceil() function instead.
 
David
-- 
David L. Cassell, OAO                     cassell@mail.cor.epa.gov
Senior computing specialist
mathematical statistician


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

Date: Mon, 05 Apr 1999 12:41:11 -0400
From: Jason Hissong <jhisson1@columbus.rr.com>
Subject: Unpack Question
Message-Id: <3708E7A7.8406DA1B@columbus.rr.com>

I am trying to unpack a C structure stored in a binary file that looks
like this:

typedef struct  _example
{
    unsigned short var_a   :   5,
                              var_b  :   5,
                              var_c  :   6;
    long l_var;
} EXAMPLE;

EXAMPLE example;

What would be my template for grabbing the parts of the unsigned short?
i.e., getting to example.var_a or example.var_b in PERL?

My template now looks like this:

"Sl"

Thanks!

Jason Hissong



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

Date: 5 Apr 1999 17:05:22 GMT
From: gbacon@itsc.uah.edu (Greg Bacon)
Subject: Re: Unpack Question
Message-Id: <7eaqgi$gkr$1@info2.uah.edu>

In article <3708E7A7.8406DA1B@columbus.rr.com>,
	Jason Hissong <jhisson1@columbus.rr.com> writes:
: I am trying to unpack a C structure stored in a binary file that looks
: like this:
: 
: typedef struct  _example
: {
:     unsigned short var_a   :   5,
:                               var_b  :   5,
:                               var_c  :   6;
:     long l_var;
: } EXAMPLE;
: 
: EXAMPLE example;
: 
: What would be my template for grabbing the parts of the unsigned short?
: i.e., getting to example.var_a or example.var_b in PERL?

This depends on your compiler.  You should consider using h2ph.

Greg
-- 
Reality is only an illusion, albeit a very persistent one.
    -- Albert Einstein


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

Date: Mon, 05 Apr 1999 13:56:48 -0400
From: Jason Hissong <jhisson1@columbus.rr.com>
Subject: Re: Unpack Question
Message-Id: <3708F960.54443DF4@columbus.rr.com>

Greg Bacon wrote:

> This depends on your compiler.  You should consider using h2ph.
>
> Greg
> --
> Reality is only an illusion, albeit a very persistent one.
>     -- Albert Einstein

Thanks for your reply,

I just tried h2ph.  It creats a perl header with only "1;" in it.  Do not
know if the structure is confusing it or not.

The compiler used to compile the application that generates this binary file
was a VC product.  I can tell you that the unsigned shorts are 16-bit in
length in the file.

-Thanks!

Jason



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

Date: Mon, 05 Apr 1999 18:40:56 GMT
From: hutcheon@iaw.on.ca (Tyler Hutcheon)
Subject: Using Perl For ErrorDocuments
Message-Id: <37090194.11674826@news.iaw.on.ca>

I am experienced in perl and unix, but I can't figure out how to get a
script of mine to work.  It is supposed to, among other things, report
on errors.  

Simulated Error: works fine
Real Error: 404 screen with 500 on the errordocument

I checked the script through, there are no errors in it..

Questions:
Is there anything special needed for responding to the error?  HTML
headders, etc?
Can I use a 1; at the end of the file? will this effect the run?
Can Full Query Strings be used in the .htaccess? ie:
	ErrorDocument 404 error.cgi?err=404
	..or does it have to be..
	ErrorDocument 404 error.cgi?404
	..or can I use them?
	ErrorDocument 404 error.cgi
	..is there a variable that says the errorcode, like
		$ENV{'REQUEST_REASON'}?

Any help is appreciated, please CC this to hutcheon@iaw.on.ca, my
email address. Thanks in advance.

Tyler Hutcheon
hutcheon@iaw.on.ca


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

Date: Mon, 05 Apr 1999 16:55:24 GMT
From: mcafee@waits.facilities.med.umich.edu (Sean McAfee)
Subject: Re: Very large regular expressions
Message-Id: <0W5O2.1290$9Y5.6674007@news.itd.umich.edu>

In article <1dpnz0b.1uuzc3f1od83jaN@p95.block1.tc5.state.ma.tiac.net>,
Ronald J Kimball <rjk@linguist.dartmouth.edu> wrote:
>Sean McAfee <mcafee@waits.facilities.med.umich.edu> wrote:
>> sub parse_form ($$\@) {
>>     my ($letter, $form, $keys) = @_;
>>     my ($n, $i, %hash) = 0;
>>     my @regex = map qr/^$_/xs, split /\n/, $form;
>>     foreach $regex (@regex) {
>>         return unless $letter =~ $regex;
>>         #  Extract the contents of the capturing parentheses:
>>         for ($i = 1; defined $$i; $i++) {
>>             $hash{$keys->[$n++]} = $$i;

>This won't work if you have capturing parentheses on different sides of
>an alternative:

True.  As I mentioned, some care is required in writing the regex.

>You could assign the results of the match to a list instead:

>return unless @matches = $letter =~ $regex;
>$hash{$keys->[$i]} = $matches[$i] for $i (0 .. $#matches);

I thought this looked spiffier than what I had, so I incorporated it into
my code, and was promptly surprised by a property of the match operator
that I hadn't known about before; namely, the way it behaves in array
context when there are no capturing parentheses in the regex:

@match = "foo" =~ /foo/;

@match now has a single element, "1".  Since some lines of my big regex
have no parentheses, I must go back to something like my original code.  I
did streamline it a bit, though:

$i = 0;  $hash{$keys[$n++]} = $$i while defined ${++$i};

>>         }
>>         $letter = $';

>Isn't this just another way of doing scalar(m//g)?

No, because I'm matching against a different regex each time through the
loop.

-- 
Sean McAfee                                                mcafee@umich.edu
print eval eval eval eval eval eval eval eval eval eval eval eval eval eval
q!q@q#q$q%q^q&q*q-q=q+q|q~q:q? Just Another Perl Hacker ?:~|+=-*&^%$#@!


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

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

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