[18913] in Perl-Users-Digest

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

Perl-Users Digest, Issue: 1081 Volume: 10

daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Thu Jun 7 09:05:54 2001

Date: Thu, 7 Jun 2001 06:05:15 -0700 (PDT)
From: Perl-Users Digest <Perl-Users-Request@ruby.OCE.ORST.EDU>
To: Perl-Users@ruby.OCE.ORST.EDU (Perl-Users Digest)
Message-Id: <991919115-v10-i1081@ruby.oce.orst.edu>
Content-Type: text

Perl-Users Digest           Thu, 7 Jun 2001     Volume: 10 Number: 1081

Today's topics:
    Re: 2 questions about flock (Villy Kruse)
    Re: 2 questions about flock (Alan Barclay)
    Re: Binary files, any suggestions? (Villy Kruse)
    Re: Binary files, any suggestions? <gnarinn@hotmail.com>
    Re: Binary files, any suggestions? <krahnj@acm.org>
    Re: Binary files, any suggestions? (Anno Siegel)
    Re: Date of Halloween (for Date::Calc module)? <sb@engelschall.com>
    Re: Date of Halloween (for Date::Calc module)? <pne-news--20010607@newton.digitalspace.net>
        Eval, the $ string, backslash escaping, and the adventu (dave)
        Executing shell command? <heinko@statoil.com>
    Re: Executing shell command? (Anno Siegel)
    Re: Executing shell command? <fei@unbounded.com>
    Re: Executing shell command? <heinko@statoil.com>
    Re: Executing shell command? (Bernard El-Hagin)
    Re: Executing shell command? (Tad McClellan)
        how to end getting and array and yet continue runny the (Lan Xing)
    Re: how to end getting and array and yet continue runny (E.Chang)
    Re: How to sort by number first then sort by english na (Anno Siegel)
        INTERFACE: in *.xs does not work (perl bug?) <makler@man.torun.pl>
    Re: Need help parsing data <josef.moellers@fujitsu-siemens.com>
    Re: Newb needs help with input from forms (Shawn Michael Taub)
        newbie perl question...please help...... <fail00@hotmail.com>
    Re: newbie perl question...please help...... (Bernard El-Hagin)
    Re: newbie perl question...please help...... <m.grimshaw@salford.ac.uk>
        newbie question: split on empty line? <gutjahr@bb-gb.bauwesen.uni-dortmund.de>
    Re: newbie question: split on empty line? (Bernard El-Hagin)
        perl, snmpv3 and ucd-snmp <Florian.Albrecht@alcatel.de>
        Digest Administrivia (Last modified: 6 Apr 01) (Perl-Users-Digest Admin)

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

Date: 07 Jun 2001 07:49:25 GMT
From: vek@pharmnl.ohout.pharmapartners.nl (Villy Kruse)
Subject: Re: 2 questions about flock
Message-Id: <slrn9hucg5.gbf.vek@pharmnl.ohout.pharmapartners.nl>

On Wed, 06 Jun 2001 16:34:20 +0100,
                Mark Grimshaw <m.grimshaw@salford.ac.uk> wrote:

>
>The major problem was file permissions.
>Lesson 1 - always check the status of open() and in particular $!.
>Lesson 2 - always check the status of open() and in particular $!.
>Lesson 3 - always check the status of open() and in particular $!.
>....
>


Also, the value of $! is meaningless unless open() returns an error status.
In particular: $! can't be used to determine if an error occurred.




Villy


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

Date: 7 Jun 2001 10:48:27 GMT
From: gorilla@elaine.furryape.com (Alan Barclay)
Subject: Re: 2 questions about flock
Message-Id: <991910905.521540@elaine.furryape.com>

In article <3B1E01A7.63D1EB2B@salford.ac.uk>,
Mark Grimshaw  <m.grimshaw@salford.ac.uk> wrote:

>$new = time;
>while(($new - $old) < 20)
>{
>        $new = time;
>}

Totally off the subject we're discussing, but this is a horrible way
to wait 20 seconds. 

You've programmed a busy loop, where the CPU will be busy working
just to delay. That would have been ok back in the days of DOS, when
you could be sure that the CPU would only have been trying to run
that one program, but if you're running Windows or any of the Unix
variants you're preventing the other programs that are running from
getting any CPU time.

If you want to wait up to 20 seconds, then you should replace the loop with:

sleep 20;

However, if any signals arrive while this sleep is running, then it
will terminate early, therefore If you want to wait exactly 20 seconds,
then you should replace it with:


$now=time;
while((time-$now)<20){
        sleep 10-time+$now,"\n";
}

This will restart the sleep if for any reason it completes early.

I'd also probably have chosen '$start' instead of '$now', to my
mind it's confusing to have something called now containing a
time in the past.


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

Date: 07 Jun 2001 07:53:30 GMT
From: vek@pharmnl.ohout.pharmapartners.nl (Villy Kruse)
Subject: Re: Binary files, any suggestions?
Message-Id: <slrn9hucnq.gbf.vek@pharmnl.ohout.pharmapartners.nl>

On Thu, 07 Jun 2001 02:14:48 GMT, Gary <gamtci@mpinet.net> wrote:
>Yes, thanks, I saw that.  I was refering to any less obvious
>potential "gotchas" of working on strictly binary data.  
>
>On input and output to the file I intend to use binmode.  But,
>I'm not that familiar with the internal workings of Perl.  
>Particularly in the area of its "context-sensitive" interpretation
>of variables, I was curious if anyone had any tips on "things
>known to fail", "never do" or "always do" type items.


If you need to convert binary data to perl variables use "pack" and
"unpack".  The binary data you read and write are just plain perl strings,
which, by the way, can hold any binary values including \0.



Villy


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

Date: Thu, 7 Jun 2001 09:35:37 +0000
From: gnari <gnarinn@hotmail.com>
Subject: Re: Binary files, any suggestions?
Message-Id: <991906537.0579131413251162.gnarinn@hotmail.com>

In article <3B1EB344.5582@mpinet.net>, Gary  <gamtci@mpinet.net> wrote:
>I have a need to read and write binary files (no expectation 
>of any sensible text in them).  I'm new to perl, although I've
>finished the Perk/Tk aspect of the program and it works fine.
>
>I've gone through several of my Perl books and there's really
>never any information on dealing with strictly binary files.
>I found "binmode" which I plan to use.
>
>I was wondering if there are any hints or suggestions before I go 
>and write this program 15 times before finally figuring it out.  
>The data in the files are strings and single chars of binary data, 
>some ASCII strings, and 32-bit and 16-bit integers.
>
>Thanks in advance for any advice.

to the other suggestions i have seen, I would add that you
should use read() instead of <>

perldoc -f binmode
perldoc -f pack
perldoc -f unpack
perldoc -f read

gnari


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

Date: Thu, 07 Jun 2001 11:04:22 GMT
From: "John W. Krahn" <krahnj@acm.org>
Subject: Re: Binary files, any suggestions?
Message-Id: <3B1F5FB5.D54A3B21@acm.org>

gnari wrote:
> 
> to the other suggestions i have seen, I would add that you
> should use read() instead of <>

because?

while ( read( IN, $_, 2048 ) ) {

# and

$/ = \2048;
while ( <IN> ) {

# are equivalent



John
-- 
use Perl;
program
fulfillment


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

Date: 7 Jun 2001 11:27:59 GMT
From: anno4000@lublin.zrz.tu-berlin.de (Anno Siegel)
Subject: Re: Binary files, any suggestions?
Message-Id: <9fnofv$9hr$2@mamenchi.zrz.TU-Berlin.DE>

According to John W. Krahn <krahnj@acm.org>:
> gnari wrote:
> > 
> > to the other suggestions i have seen, I would add that you
> > should use read() instead of <>
> 
> because?
> 
> while ( read( IN, $_, 2048 ) ) {
> 
> # and
> 
> $/ = \2048;
> while ( <IN> ) {
> 
> # are equivalent

Well, yes.  But it isn't uncommon to see <> used with binary files
with the default $/.  A warning against *that* practice seems
appropriate.

Anno


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

Date: Thu, 7 Jun 2001 13:54:49 +0200
From: Steffen Beyer <sb@engelschall.com>
Subject: Re: Date of Halloween (for Date::Calc module)?
Message-Id: <92qnf9.83f.ln@imperia.net>

In comp.lang.perl.misc Philip Newton <pne-news-20010607@newton.digitalspace.net> wrote:

>> It's always October 31
> 
> Specifically, it's "Hallowe'en" < "All Hallows Eve[n]", so it's the
> evening (or, by extension, the whole day) before All Hallows [Day], or
> All Saints [Day] ("Allerheiligen" in German), which is 1 November.
> Incidentally, the day after that, 2 November, is another "all": All
> Souls [Day] ("Allerseelen").
> 
> http://www.loc.gov/folklife/halloween.html may also be interesting.
> (There are also tons of other links you could look for with "Halloween
> All Hallows All Saints" or similar keywords, for example,
> http://www.ewtn.com/library/MARY/HALLWEEN.HTM .)

Excellent!!!

This is exactly the kind of detailed information I was hoping for!!

Thanks a lot!!!!!!!!!!!!!!!!!

I suppose that this day (being no official holiday in the U.S.) doesn't
follow the rule that if it falls on a weekend, it is substituted by the
following Monday (like most of the offical U.S. american holidays)?
Is that correct?

> Cheers,
> Philip

Best regards,
-- 
    Steffen Beyer <sb@engelschall.com>
    (This message may not be replyable. Use address on line above instead!)
    http://www.engelschall.com/u/sb/whoami/ (Who am I)
    http://www.engelschall.com/u/sb/gallery/ (Fotos Brasil, USA, ...)
    http://www.engelschall.com/u/sb/download/ (Free Perl and C Software)


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

Date: Thu, 07 Jun 2001 14:33:22 +0200
From: Philip Newton <pne-news--20010607@newton.digitalspace.net>
Subject: Re: Date of Halloween (for Date::Calc module)?
Message-Id: <13tuhtcdmua2ao3sd65g05f4lb6hfstvde@4ax.com>

On Thu, 7 Jun 2001 13:54:49 +0200, Steffen Beyer <sb@engelschall.com>
wrote:

> I suppose that this day (being no official holiday in the U.S.) doesn't
> follow the rule that if it falls on a weekend, it is substituted by the
> following Monday (like most of the offical U.S. american holidays)?
> Is that correct?

As I understand it, yes -- Halloween is *always* on 31 October.

Cheers,
Philip
-- 
Philip Newton <nospam.newton@gmx.li>
That really is my address; no need to remove anything to reply.
If you're not part of the solution, you're part of the precipitate.


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

Date: 7 Jun 2001 05:59:13 -0700
From: usted@cyberspace.org (dave)
Subject: Eval, the $ string, backslash escaping, and the adventures thereof
Message-Id: <e2c00ae.0106070459.1ab1d8a@posting.google.com>

$translate_dollar_sign = "\$$key =~ s/\$/(dollar-sign)/g";
eval "$translate_dollar_sign";
if ($@) {bail ("Error stripping \$$key $@");} 

This code replaces the end of line with "(dollar-sign)" when I want it
to replace the character '$'.  Backslashing doesn't help, it is still
a $ EOL to the regexp.  I thought that maybe the eval was affecting
it, but the eval doesn't have any variables to interpret.  Any ideas?

Thanks,

dave


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

Date: Thu, 07 Jun 2001 11:52:29 +0200
From: Heine Kolltveit <heinko@statoil.com>
Subject: Executing shell command?
Message-Id: <3B1F4EDD.7EC8460E@statoil.com>

Can someone tell me how i execute a simple command in unix (eg. ls)(and
get the result into the program as an String or something)?



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

Date: 7 Jun 2001 10:00:06 GMT
From: anno4000@lublin.zrz.tu-berlin.de (Anno Siegel)
Subject: Re: Executing shell command?
Message-Id: <9fnjb6$54a$1@mamenchi.zrz.TU-Berlin.DE>

According to Heine Kolltveit  <heinko@statoil.com>:
> Can someone tell me how i execute a simple command in unix (eg. ls)(and
> get the result into the program as an String or something)?
> 

Look at the perlop documentation and search for "qx".

Anno


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

Date: Thu, 7 Jun 2001 03:04:40 -0700
From: "Fei" <fei@unbounded.com>
Subject: Re: Executing shell command?
Message-Id: <9fnjfe$fi8$1@taliesin.netcom.net.uk>


"Heine Kolltveit" <heinko@statoil.com> 撰寫於郵件
news:3B1F4EDD.7EC8460E@statoil.com...
> Can someone tell me how i execute a simple command in unix (eg. ls)(and
> get the result into the program as an String or something)?
>
perldoc -q system


 $output_string = `ls`;




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

Date: Thu, 07 Jun 2001 14:04:02 +0200
From: Heine Kolltveit <heinko@statoil.com>
Subject: Re: Executing shell command?
Message-Id: <3B1F6DB2.FEC3C248@statoil.com>

The admin hasn't installed perldoc. Can you give me some more information?
I've tried this:

system("ls");

and it executes the command, but I can't seem to get the result into a
variable.

Help please...

Fei wrote:

> "Heine Kolltveit" <heinko@statoil.com> 撰寫於郵件
> news:3B1F4EDD.7EC8460E@statoil.com...
> > Can someone tell me how i execute a simple command in unix (eg. ls)(and
> > get the result into the program as an String or something)?
> >
> perldoc -q system
>
>  $output_string = `ls`;



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

Date: Thu, 7 Jun 2001 12:15:35 +0000 (UTC)
From: bernard.el-hagin@lido-tech.net (Bernard El-Hagin)
Subject: Re: Executing shell command?
Message-Id: <slrn9hurcu.8e2.bernard.el-hagin@gdndev25.lido-tech>

[fixed jeopardy quote]

On Thu, 07 Jun 2001 14:04:02 +0200, Heine Kolltveit <heinko@statoil.com>
wrote:
>> "Heine Kolltveit" <heinko@statoil.com> 撰寫於郵件
>> news:3B1F4EDD.7EC8460E@statoil.com...
>> > Can someone tell me how i execute a simple command in unix (eg. ls)(and
>> > get the result into the program as an String or something)?
>> >
>> perldoc -q system
>>
>>  $output_string = `ls`;
    ^^^^^^^^^^^^^^^^^^^^^^

>
>The admin hasn't installed perldoc. Can you give me some more information?

Use the on-line documentation, then:

http://www.perl.com/pub/v/documentation

>I've tried this:
>
>system("ls");
>
>and it executes the command, but I can't seem to get the result into a
>variable.

The solution is right there in the post you jeopardy quoted!

Cheers,
Bernard
--
perl -l54e's yyw q q tvmrx "h\ywx ersxliv zivp legoiv"qiy;y #a-zA-Z#d-gu-z#
chefghijklmnopqrstuvwxyzcJab-def-uPwxyzc;s j j s u u s t t s r r s
ppevalpereeteueje'


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

Date: Thu, 7 Jun 2001 08:02:46 -0400
From: tadmc@augustmail.com (Tad McClellan)
Subject: Re: Executing shell command?
Message-Id: <slrn9hurb6.9bk.tadmc@tadmc26.august.net>

Heine Kolltveit <heinko@statoil.com> wrote:

>The admin hasn't installed perldoc. 


It is part of a normal perl install. (S)He had to do something to cause
it to not be installed, ie. a conscious decision to not install it.

Please note that the snippiness in my post is not directed at you,
but at your foolish admin.


>Can you give me some more information?


Can your sysadmin give you some more information?

If they were doing their job correctly, you wouldn't have to bother
them with your Perl questions, you'd be able to find answers yourself.

But since they aren't, ask _them_ your Perl questions. Have your
coworkers ask them their Perl questions too. Ask them again the
next day if they have not been answered. Continue every day
until you get an answer.

Shouldn't take too long to convince them to do their job correctly  :-)


>Help please...


Ask the sysadmin who is withholding information from you to be
free with information. It doesn't cost much.


[snip backwards quoted text]

-- 
    Tad McClellan                          SGML consulting
    tadmc@augustmail.com                   Perl programming
    Fort Worth, Texas


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

Date: 7 Jun 2001 01:47:11 -0700
From: lan_xing@hotmail.com (Lan Xing)
Subject: how to end getting and array and yet continue runny the next statement?
Message-Id: <2a6ee727.0106070047.68fe698b@posting.google.com>

Ok. I am a newbie.. 
My Perl book teach you how to do Ctrl-D in UNIX system to stop the
input
but it says it will continue running the rest of the statements after
it. But I am using a Windoze NT how do I do that?? Why doesn't the
next line print? I tried Ctrl-Z, Ctrl-C and Ctrl-Break but all of them
exit the program.. without printing "Print Me!!!".. help pls.



@line = <STDIN>;
print ("Print ME!!!");


I wish all the previous post regarding this but still no solutions.

Thanks, 
Lan Xing


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

Date: Thu, 07 Jun 2001 10:26:21 GMT
From: echang@netstorm.net (E.Chang)
Subject: Re: how to end getting and array and yet continue runny the next statement?
Message-Id: <Xns90B942000B941echangnetstormnet@207.106.92.86>

lan_xing@hotmail.com (Lan Xing) wrote in
<2a6ee727.0106070047.68fe698b@posting.google.com>: 

> Ok. I am a newbie.. 
> My Perl book teach you how to do Ctrl-D in UNIX system to stop the
> input
> but it says it will continue running the rest of the statements
> after it. But I am using a Windoze NT how do I do that?? Why
> doesn't the next line print? I tried Ctrl-Z, Ctrl-C and Ctrl-Break
> but all of them exit the program.. without printing "Print Me!!!"..
> help pls. 
> 
> @line = <STDIN>;
> print ("Print ME!!!");
>
>I wish all the previous post regarding this but still no solutions.
 
I don't really understand what is happening here, but with some 
experimentation found that printing a newline solves the problem 
consistently (using Ctrl-Z as the end-of-file character).

  @line = <STDIN>;
  print STDOUT "\nPrint ME!!!";

The newline itself does not appear in the output, nor does any other 
text printed before the newline - for example, with   

  @line = <STDIN>;
  print STDOUT "Don't print me?\nPrint ME!!!";

only the 'Print ME!!!' is printed.  It would seem that < > is waiting 
for a final terminating newline on the input even after the end of 
file.  I assume the explanation is DOS rather than Perl .

-- 
EBC


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

Date: 7 Jun 2001 07:20:52 GMT
From: anno4000@lublin.zrz.tu-berlin.de (Anno Siegel)
Subject: Re: How to sort by number first then sort by english name?
Message-Id: <9fna0k$ml8$1@mamenchi.zrz.TU-Berlin.DE>

According to Todd Smith <todd@designsouth.net>:
> 
> "Anno Siegel" <anno4000@lublin.zrz.tu-berlin.de> wrote in message
> news:9flkh4$ooh$1@mamenchi.zrz.TU-Berlin.DE...
> >
> > The placement of chomp in a sort routine is clearly wrong, not to
> > mention inefficient and ugly.  Yet the DWIMmish nature of chomp
> > (only chop $/ if it is there) lets a naive programmer get away with
> > it and never notice something's amiss.  Then the code spreads...
> >
> > Good old chop would at least have left traces.
> >
> 
> So it's naive to use chomp even though that's what it's there for? I think

Of course not, and I didn't say so.

> it would be stupid to not use it just because chop can do the same thing
> with more code. There's always a way to do something with more code, but
> that doesn't mean it's better.

You missed the point.  I have nothing against chomp when used
appropriately, which is most of the time.  But the example shows
how its sophisticated nature makes it possible to use it in
inappropriate ways and never realize you do.

> And you think that
> 
> chomp ($a, $b);
> 
> is uglier than
> 
> chop $a while $a =~ /\n$/;
> chop $b while $b =~ /\n$/;
> 
> I don't think so.

Aesthetics aside, these do different things.

Anno


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

Date: 7 Jun 2001 09:16:00 GMT
From: Piotr Klaban <makler@man.torun.pl>
Subject: INTERFACE: in *.xs does not work (perl bug?)
Message-Id: <9fngog$76v$1@flis.man.torun.pl>

Hi,

I tried to use INTERFACE: keyword in my xs file,
(described in perlxs manual), and it does not work.
Even the manual example:

<test.xs>
#include "EXTERN.h"
#include "perl.h"
#include "XSUB.h"

extern int multiply(int a, int b) {};
extern int divide(int a, int b) {};
extern int add(int a, int b) {};
extern int subtract(int a, int b) {};

MODULE = test           PACKAGE = test

int
interface_s_ss(arg1, arg2)
    int        arg1
    int        arg2
  INTERFACE:
    multiply divide
    add subtract
</test.xs>

complains during compilation:

gcc -c -I/usr/local/include -I/usr/lib/glib/include -fno-st ict-aliasing
-I/usr/local/include -O -DVERSION=\"0.01\" -DXS_VERSION=\"0.01\" -fPIC
-I/usr/local/opt/perl5.6/lib/5.6.0/sun4-solaris-64int/CORE test.c
test.c: In function `XS_test_interface_s_ss':
test.c:32: parse error before `cv'
test.c:32: parse error before `)'
Exit 1

The test.c part around 32 line:

     20 #line 21 "test.c"
     21 XS(XS_test_interface_s_ss)
     22 {
     23     dXSARGS;
     24     dXSFUNCTION(int);
     25     if (items != 2)
     26         Perl_croak(aTHX_ "Usage: test::interface_s_ss(arg1, arg2)");
     27     {
     28         int     arg1 = (int)SvIV(ST(0));
     29         int     arg2 = (int)SvIV(ST(1));
     30         int     RETVAL;
     31         dXSTARG;
     32         XSFUNCTION = XSINTERFACE_FUNC(int,cv,XSANY.any_dptr);
     33 
     34         RETVAL = XSFUNCTION(arg1, arg2);
     35         XSprePUSH; PUSHi((IV)RETVAL);
     36     }
     37     XSRETURN(1);
     38 }

And cv is neither local nor global variable in XS_test_interface_s_ss
function. It is local variable in test_boot procedure.
I thing it is a bug in perl XS interface design.
I did not find any INTERFACE: keyword in popular perl modules.

perl -v output:

This is perl, v5.6.0 built for sun4-solaris-64int
[...]

-- 
Piotr Klaban


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

Date: Thu, 07 Jun 2001 09:36:03 +0200
From: Josef Moellers <josef.moellers@fujitsu-siemens.com>
Subject: Re: Need help parsing data
Message-Id: <3B1F2EE3.CD3B6AD2@fujitsu-siemens.com>

Zydas wrote:

>  while (<STDIN>){
>  @line =3D split(/,/);
>  printf
> "%-2.2s%-15.15s%-3.3s%-30.30s%-7.7s%-8.8s%-5.5s%-2.2s%-4.4s%-10.10s%-30=
=2E30s%-8.8s%-2.2s%-30.30s%-5.5s%-35.35s%-35.35s%-35.35s%-19.19s%-2.2s%-9=
=2E9s\n%-2.2s%-9.9s%-8.8s%-7.7s%-8.8s%-6.6s%-5.5s%-30.30s%-30.30s\n%-2.2s=
%-20.20s\n%-2.2s%-20.20s%-30.30s%-13.13s%-10.10s%-9.9s%-2.2s%-9.9s%-2.2s%=
-30.30s%-25.25s%-25.25s\n",
> $line[0], $line[1], $line[2], $line[3], $line[4], $line[5], $line[6],
> $line[7], $line[8], $line[9], $line[10], $line[11], $line[12],
> $line[13], $line[14], $line[15], $line[16], $line[17], $line[18],
> $line[19], $line[20], $line[21], $line[22], $line[23], $line[24],
> $line[25], $line[26], $line[27], $line[28], $line[29], $line[30],
> $line[31], $line[32], $line[33], $line[34], $line[35], $line[36],
> $line[37], $line[38], $line[39], $line[40], $line[41], $line[42],
> $line[43];
> }

> Here's my problem. I need to have the script process several lines of
> text at the same time. The first line should be processed the way it
> currenty is. However line 2 and on should not display/process the
> first 20 fields of the list. Thus, if I process two lines of data:

TMTOWTDI:

$firstline =3D <STDIN>;
@line =3D split /,/, $firstline;
printf as above;
while (<STDIN>) {
   @line =3D split /,/;
   printf with fewer fields;
}

or

$fmt1 =3D "first part of format string that prints first 20 fields";
$fmt2 =3D "rest of format string";
$start =3D 0;
while (<STDIN>) {
    @line =3D split /,/;
    @line =3D @line[$start .. $#line];
    printf $fmt1 . $fmt2, @line;
    $start =3D 20;
    $fmt1 =3D "";
}

I haven't tested these thoroughly, though.

Josef
-- =

Josef M=F6llers (Pinguinpfleger bei FSC)
	If failure had no penalty success would not be a prize
						-- T.  Pratchett


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

Date: 7 Jun 2001 06:03:00 -0700
From: shawntaub@yahoo.ca (Shawn Michael Taub)
Subject: Re: Newb needs help with input from forms
Message-Id: <d8fa40ef.0106070502.47aec84@posting.google.com>

Excellent.  This will make my life much easier.  Thanx for the help. 
Now all I need to do is find a good quick tutorial on CGI.pm and the
module itself.


> OK... writing a CGI script like the one you showed us is like building a 
> car from scratch when all you really want to do is go somewhere.  The code 
> you showed is the sort of thing that *every* Perl CGI script has to do.  
> Why should you or anyone else have to write it over and over again?  All 
> that stuff has been "encapsulated" into a module of functions, named 
> CGI.pm, that is included with the standard distribution of Perl, and 
> should be available on any server that you want to run CGI script on.

And this is why I wanted to know what the heck this script was.  I
knew it would be a waste of my time and effort, that's why I love copy
and paste so much.  But if I can save lines on my program to make it
run faster and more efficient, then by all means, this is too cool.

Anyhoo, I'm gonna rip apart this script for a second, so bear with me
as I try to understand it.

> use strict;             # Does a lot of error checking on your Perl code.

I'm assuming this is something like Option Explicit in Visual Basic. 
Also, this use thing, is this like C's include command?  When I
started programming, I was using a piece of (stuff) language called
Turing, which got me started in using include commands to bring my own
self-made functions, procedures, and whatnots into programs without
wasting more lines of code, just including it all into one file. 
Actually, for one program, I made it solely of include files and made
it the EXE.  Needless to say, that one didn't work, but otherwise
including stuff is good fun.

> use CGI qw/:standard/;  # Enables the CGI.pm module, and tells it you
>                         #  want to use the "standard" set of functions
>                         #  from it.
> 
> # Get the values of the CGI parameters.  It doesn't matter whether they 
> # came from GET or POST.  This contains all the dinking around with 
> # environment variables, parsing their contents with regular expressions 
> # etc., which your sample script showed in all its naked and ugly glory.

Just wondering.  Going back to the example that I found (here's just a
piece of it)
---start script
# separate each keyword
foreach ( split( /&/, $temp ) ) {
    # separate the keys and values
    ( $key, $val ) = split( /=/, $_, 2 );

    # translate + to spaces
    $key=~s/\+/ /g;
    $val=~s/\+/ /g;

    # translate %xx codes to characters
    $key=~s/%([0-9a-f]{2})/pack("c",hex($1))/gie;
    $val=~s/%([0-9a-f]{2})/pack("c",hex($1))/gie;

    print "$key = $val\n";
}
---end script
I could just have easily done some really cheezy assignment statement
like
$FORM{$key} = $val
instead of that print thing and use the hash %FORM to do all my
reffering to what was given from the form.  What does CGI.pm do for
referring to input from the form?  As a general rule, I like things to
be in a complete order when I'm programming so I know exactly what I'm
refferring to.  That's why I prefer user-defined types over 2d arrays
(both of which I've been told Perl doesn't like much).  With this
hash, all I need to know is what the form looked like and the names of
the stuff from the form.  How can CGI.pm simplify this?

> # Send the default HTTP headers, including the all-important 
> # "Content-Type:" which is set to text/plain by default.
> 
> print header;

What if I wanted a different HTTP header?  What if I wanted, say,
text/html or image/jpeg?

> CGI.pm also provides functions which can do the HTML for you.
> Instead of printing a here-document literally, I could have done this:
> 
>   print start_html("JB's Example"),
>         h1("JB's Example"),
>         p("Hello, $Name!  Your favorite color is $Color."),
>         end_html;
> 
> This would have sent out all the appropriate HTML tags along with the
> given text.

Not a chance I'll use this.  I'm lazy, yes, but not lazy enough to
stop me from making something in an HTML editor and copy and paste. 
But it looks like a nice feature.

Thanks again.
Shawn Michael Taub


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

Date: Thu, 7 Jun 2001 21:58:02 +1200
From: "fail006" <fail00@hotmail.com>
Subject: newbie perl question...please help......
Message-Id: <9fnika$ag$1@lust.ihug.co.nz>

Hi,
I am writing a small program that can calculator some IP addresses.
I would like to know when a user enters an IP address in dotted decmial
format, e.g
192.168.44.4, how can i store this and separate each of the four octets. So
i want to able to operate on each of the 4 octets, e,g 192 168 44 and 4. So
how do i get rid of the decimal point between each octet.

Thanks





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

Date: Thu, 7 Jun 2001 10:06:18 +0000 (UTC)
From: bernard.el-hagin@lido-tech.net (Bernard El-Hagin)
Subject: Re: newbie perl question...please help......
Message-Id: <slrn9hujqg.8e2.bernard.el-hagin@gdndev25.lido-tech>

On Thu, 7 Jun 2001 21:58:02 +1200, fail006 <fail00@hotmail.com> wrote:
>Hi,
>I am writing a small program that can calculator some IP addresses.
>I would like to know when a user enters an IP address in dotted decmial
>format, e.g
>192.168.44.4, how can i store this and separate each of the four octets. So
>i want to able to operate on each of the 4 octets, e,g 192 168 44 and 4. So
>how do i get rid of the decimal point between each octet.

$_ = '192.168.44.4';

for(split/\./){
	#do something with octet;
}

More info:

perldoc -f split

Cheers,
Bernard
--
perl -l54e's yyw q q tvmrx "h\ywx ersxliv zivp legoiv"qiy;y #a-zA-Z#d-gu-z#
chefghijklmnopqrstuvwxyzcJab-def-uPwxyzc;s j j s u u s t t s r r s
ppevalpereeteueje'


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

Date: Thu, 07 Jun 2001 11:12:07 +0100
From: Mark Grimshaw <m.grimshaw@salford.ac.uk>
Subject: Re: newbie perl question...please help......
Message-Id: <3B1F5377.4F333F9C@salford.ac.uk>



fail006 wrote:
> 
> Hi,
> I am writing a small program that can calculator some IP addresses.
> I would like to know when a user enters an IP address in dotted decmial
> format, e.g
> 192.168.44.4, how can i store this and separate each of the four octets. So
> i want to able to operate on each of the 4 octets, e,g 192 168 44 and 4. So
> how do i get rid of the decimal point between each octet.
> 
> Thanks

Try:
@array = split(/\./, $ipaddress);


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

Date: 07 Jun 2001 12:06:33 +0200
From: Stephan Gutjahr <gutjahr@bb-gb.bauwesen.uni-dortmund.de>
Subject: newbie question: split on empty line?
Message-Id: <3b1f522b$1@netnews.web.de>

Hello,
I want to read data from a file. The file contains something like


sdf    asdf
sdf    lkjj 


dsfj   asdf
efj     sldk


Now I want to split it up into two  array on the empty line. the folllowing 
gives me only the last line.
 why?


open(KEIN, "dhy1h.txt") or die "Fehler: $!\n";
while ($line = <KEIN>)
      {
      @blocks = split "\n", $line;
      }


Any comments would be appreciated.
stephan

-- 
__________________________________________________________
News suchen, lesen, schreiben mit http://newsgroups.web.de


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

Date: Thu, 7 Jun 2001 10:21:00 +0000 (UTC)
From: bernard.el-hagin@lido-tech.net (Bernard El-Hagin)
Subject: Re: newbie question: split on empty line?
Message-Id: <slrn9huklu.8e2.bernard.el-hagin@gdndev25.lido-tech>

On 07 Jun 2001 12:06:33 +0200, Stephan Gutjahr
<gutjahr@bb-gb.bauwesen.uni-dortmund.de> wrote:
>Hello,
>I want to read data from a file. The file contains something like
>
>
>sdf    asdf
>sdf    lkjj 
>
>
>dsfj   asdf
>efj     sldk
>
>Now I want to split it up into two  array on the empty line.

The following assumes you've got two blank lines between
records. If that's different change $/ accordingly.

$/ = "\n\n";
push @a1, scalar <DATA>;
push @a2, scalar <DATA>;


>the folllowing gives me only the last line.
>why?
>
>open(KEIN, "dhy1h.txt") or die "Fehler: $!\n";
>while ($line = <KEIN>)
>      {
>      @blocks = split "\n", $line;
>      }

$line contains only one line of the file at a time. What you're
doing is splitting one line of text on the newline in effect
getting that same line (minus the newline). You're doing this
once for each line in the file and since the last line of the file
is last :-) that's what you're getting at the end in your array.

Cheers,
Bernard
--
perl -l54e's yyw q q tvmrx "h\ywx ersxliv zivp legoiv"qiy;y #a-zA-Z#d-gu-z#
chefghijklmnopqrstuvwxyzcJab-def-uPwxyzc;s j j s u u s t t s r r s
ppevalpereeteueje'


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

Date: Thu, 07 Jun 2001 12:21:42 +0200
From: Florian Albrecht <Florian.Albrecht@alcatel.de>
Subject: perl, snmpv3 and ucd-snmp
Message-Id: <3B1F55B6.DE6A3022@alcatel.de>

Hi there!

In order to use SNMPv3 with Perl, I downloaded ucd-snmp-4.2.1-1.win for
my WinNT system. This is a file with binaries, because I had some
troubles in compiling the sources. Now I have new troubles:
1. How do I use (install) the binaries?
2. How can I use (install) the Perl interface? (The Makefile.PL asks me
where the inculde files of ucd-snmp are, but there are _no_ include
files! Isn't there a simple way to install this, e.g. just copying a
file somewhere?)

thanx in advance
;-) Flo


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

Date: 6 Apr 2001 21:33:47 GMT (Last modified)
From: Perl-Users-Request@ruby.oce.orst.edu (Perl-Users-Digest Admin) 
Subject: Digest Administrivia (Last modified: 6 Apr 01)
Message-Id: <null>


Administrivia:

The Perl-Users Digest is a retransmission of the USENET newsgroup
comp.lang.perl.misc.  For subscription or unsubscription requests, send
the single line:

	subscribe perl-users
or:
	unsubscribe perl-users

to almanac@ruby.oce.orst.edu.  

To submit articles to comp.lang.perl.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.

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 V10 Issue 1081
***************************************


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