[17869] in Perl-Users-Digest

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

Perl-Users Digest, Issue: 29 Volume: 10

daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Wed Jan 10 09:05:36 2001

Date: Wed, 10 Jan 2001 06:05:18 -0800 (PST)
From: Perl-Users Digest <Perl-Users-Request@ruby.OCE.ORST.EDU>
To: Perl-Users@ruby.OCE.ORST.EDU (Perl-Users Digest)
Message-Id: <979135518-v10-i29@ruby.oce.orst.edu>
Content-Type: text

Perl-Users Digest           Wed, 10 Jan 2001     Volume: 10 Number: 29

Today's topics:
    Re: ASCII to integer conversion <flegga@uk.ibm.com>
    Re: ASCII to integer conversion <cliff@*MYLASTNAMEHERE*.nl>
    Re: ASCII to integer conversion <cliff@*MYLASTNAMEHERE*.nl>
    Re: ASCII to integer conversion <cliff@*MYLASTNAMEHERE*.nl>
    Re: ASCII to integer conversion <jhelman@wsb.com>
    Re: ASCII to integer conversion <jhelman@wsb.com>
    Re: ASCII to integer conversion <jhelman@wsb.com>
    Re: ASCII to integer conversion (Martien Verbruggen)
    Re: ASCII to integer conversion (Martien Verbruggen)
    Re: ASCII to integer conversion (Martien Verbruggen)
    Re: ASCII to integer conversion <flavell@mail.cern.ch>
    Re: CGI vs Javascript dropdowns damian_taylor@my-deja.com
    Re: counting lines in a file (Richard Zilavec)
    Re: counting lines in a file <krahnj@acm.org>
    Re: counting lines in a file (Rafael Garcia-Suarez)
    Re: counting lines in a file (Tad McClellan)
        Finding logged on user <afried@mediaone.net>
    Re: Finding logged on user (Rafael Garcia-Suarez)
        Frames <ee@jpcvgg.net>
        Got error when following perlxstut <john@imining.com.tw>
    Re: Help this newbie learn please :) <domning@t-online.de>
    Re: Help this newbie learn please :) (Helgi Briem)
    Re: Help this newbie learn please :) <peb@bms.umist.ac.uk>
    Re: Help this newbie learn please :) <dperham@dperham.eng.tvol.net>
    Re: HTML stripper (James Kufrovich)
    Re: Is $? set when using backticks to issue a system co <geoff-at-farmline-dot-com@127.0.0.1>
    Re: List Results (Tad McClellan)
        Digest Administrivia (Last modified: 16 Sep 99) (Perl-Users-Digest Admin)

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

Date: Wed, 10 Jan 2001 10:04:36 +0000
From: Andrew Flegg <flegga@uk.ibm.com>
Subject: Re: ASCII to integer conversion
Message-Id: <3A5C33B4.F242062E@uk.ibm.com>

Clifford Pennock wrote:
> "Jürgen Exner" wrote:
> > Don't quite agree. Even in C the substring function (regardless if 
> > you use the library function or do some weird pointer arithmetic of 
> > your own) would still yield a string "1234m" and if you pass it on 
> > to the next program it will still be a string.
> 
> Again, that is why one would use the atoi funtion, as in
> 
>   a_number = index( a_string, ',' );
>   sprintf( shellcommand, "a_program %d", atoi( ++a_number ) );
> 
> So the question remains: what's the easy way to do that in Perl?

Abigail's already answered (and the same way I'd do it, woohoo! ;-)):

  my ($a_number) = $a_string =~ m/(\d+)/;

This'd pull out the first number in $a_string without atoi(),
substr() or any other non-Perl-like function ;-)

Cheers,

Andrew

-- 
Andrew Flegg -- my opinions are my own, not my employers.


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

Date: Wed, 10 Jan 2001 11:53:34 +0100
From: Clifford Pennock <cliff@*MYLASTNAMEHERE*.nl>
Subject: Re: ASCII to integer conversion
Message-Id: <93hfnu$6ib$1@news.news-service.com>

Uri Guttman wrote:
> 
> >>>>> "CP" == Clifford Pennock <cliff@*MYLASTNAMEHERE*.nl> writes:
> 
>   CP> Oh jump of your soapbox, Uri. The quotes were not included to
>   CP> indicate "strings" or whatever. Or do I now need to write my
>   CP> english in Perl syntax also?
> 
> this is a perl newsgroup, not an english one. if you are refering to
> values, typing the proper value is important.

Then what is the proper way to refer to the value of scalars in plain
English?

> you were concerned with converting strings to integers.

No, I am concerned about converting scalars that contain something like
1234m/s is the speed of the object (I wanted to use quotes here so
people won't get confused about what is part of the scalar and what
isn't, but that would be wrong in your opinion) to a scalar that
contains 1234 only.

> you type what should be an integer value
> as a string with quotes.

No, since I wasn't typing a piece of code here.

> that is not an accurate way to describing your
> data. i have no idea what is going on in your head and PSI::ESP doesn't
> always work so well.

That's because you didn't call the constructor properly:

use PSI::ESP;

$mental_ability = PSI::ESP->new( UseCommonSenseFirst=>1 );

> given the thread, you have to assume you had the
> wrong format for the data.

Given the thread, there is no such thing as wrong data format.


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

Date: Wed, 10 Jan 2001 12:01:41 +0100
From: Clifford Pennock <cliff@*MYLASTNAMEHERE*.nl>
Subject: Re: ASCII to integer conversion
Message-Id: <93hg77$6ss$1@news.news-service.com>

Jeff Helman wrote:
> 
> On Tue, 09 Jan 2001 23:36:13 +0100, Clifford Pennock
> <cliff@*MYLASTNAMEHERE*.nl> wrote:
> 
> >Uri Guttman wrote:
> >>
> >> then your program has a BUG in it. you didn't extract the number, you
> >> extracted a string which starts with a number. it is YOUR fault, not
> >> perl's. learn perl and stop thinking in c. scalars hold numbers or
> >> strings and there is no need to explicitly convert them. it is on your
> >> (the programmer's) head to make sure the data is meaningful in the
> >> proper contxt.
> >>
> >> sheesh!
> >>
> >> uri
> >
> >Jesus Uri, read the f*cking thread. I'm not having any problems here
> >with Perl nor do any of my Perl programs, I'm just pointing out that
> >Perl's behavior can cause problems if you don't beware. With typecasting
> >you get an error at compile time if your variable is of the wrong type.
> >Perl's "I don't care 'cos there all scalars" can be cumbersome from time
> >to time. You *always* have to take into account that Perl can handle
> >something differently than you (or the user) expects.
> 
> These "problems" are present with any programming language, C, Perl,
> COBOL, whatever.  The onus is on the programmer to make sure that the
> supplied data meets with the needs of the next statement.  It doesn't
> matter what language you're in, you still have to remember that if you
> make it idiot-proof, somebody, somewhere, is busily constructing a
> better idiot.
> 
> So you are looking for an integer in a data stream (file, console,
> doesn't matter).  In C, you are correct, if you call atoi() on a
> non-numeric sequence, the program is going to toss an exception and
> die.

Actually, it will return 0.

> Such is the nature of typed languages.  In non-typed languages,
> if you want an integer, it's your job to make sure that you got one
> (regular expressions are here for a reason).  If you didn't, rethink
> the interface.

And that is exactly the point of this thread. How to convert a scalar
that starts with a numeric sequence followed by a non-numeric sequence
to the numeric part only. The answer people were giving was: "There's no
need to.".

Well excuse me, but there's always a need to.

> I've spent more hours than I care to count trying to grok the many
> different ways that a user can enter a phone number.  Dots, dashes,
> parenthesis, slashes; It seems that no matter what you tell your user,
> they will come up with something different.

Tell me about it. People are still asking about the "any"-key... :)


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

Date: Wed, 10 Jan 2001 12:17:12 +0100
From: Clifford Pennock <cliff@*MYLASTNAMEHERE*.nl>
Subject: Re: ASCII to integer conversion
Message-Id: <93hh48$7kj$1@news.news-service.com>

Andrew Flegg wrote:
> 
> >   a_number = index( a_string, ',' );
> >   sprintf( shellcommand, "a_program %d", atoi( ++a_number ) );
> >
> > So the question remains: what's the easy way to do that in Perl?
> 
> Abigail's already answered (and the same way I'd do it, woohoo! ;-)):
> 
>   my ($a_number) = $a_string =~ m/(\d+)/;
> 
> This'd pull out the first number in $a_string without atoi(),
> substr() or any other non-Perl-like function ;-)

Thanks!

I never got past his first "If you would know the very basics of Perl,
you'd know how silly the question is."-answer. Whenever I see an answer
like that my hair starts to rise in the back of my neck and I tend to
not read any subsequent answers from the same person. Like he never was
a newbie once.


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

Date: Wed, 10 Jan 2001 11:53:25 GMT
From: Jeff Helman <jhelman@wsb.com>
Subject: Re: ASCII to integer conversion
Message-Id: <i0jo5t0d66j35fap8urt0qsbql4qpa1olj@4ax.com>

On Wed, 10 Jan 2001 12:01:41 +0100, Clifford Pennock
<cliff@*MYLASTNAMEHERE*.nl> wrote:

>Jeff Helman wrote:
>> 
>> So you are looking for an integer in a data stream (file, console,
>> doesn't matter).  In C, you are correct, if you call atoi() on a
>> non-numeric sequence, the program is going to toss an exception and
>> die.
>
>Actually, it will return 0.

Sory.  My knowledge of C is suspect at best.  I can usually read it,
just don't ask me to write it.

>And that is exactly the point of this thread. How to convert a scalar
>that starts with a numeric sequence followed by a non-numeric sequence
>to the numeric part only. The answer people were giving was: "There's no
>need to.".
>
>Well excuse me, but there's always a need to.

Only for some definitions of "always".  If you feel the need to check,
then do so:

$var =~ s/^(\d+).+/$1/s;

JH


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

Date: Wed, 10 Jan 2001 12:24:40 GMT
From: Jeff Helman <jhelman@wsb.com>
Subject: Re: ASCII to integer conversion
Message-Id: <50lo5tcc5qsfgc81uact0sstrnqbo9b60j@4ax.com>

On Wed, 10 Jan 2001 11:53:25 GMT, Jeff Helman <jhelman@wsb.com> wrote:

>$var =~ s/^(\d+).+/$1/s;

Whoops.  Make that:

$var =~ s/\D.+//s;

I should know better than to think first thing in the morning.  This
one will also strings that don't start with a number correctly.

JH



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

Date: Wed, 10 Jan 2001 12:32:57 GMT
From: Jeff Helman <jhelman@wsb.com>
Subject: Re: ASCII to integer conversion
Message-Id: <1klo5t0r52gei1ugnjpp7913b42104s5dn@4ax.com>

On Wed, 10 Jan 2001 12:24:40 GMT, Jeff Helman <jhelman@wsb.com> wrote:

>On Wed, 10 Jan 2001 11:53:25 GMT, Jeff Helman <jhelman@wsb.com> wrote:
>
>>$var =~ s/^(\d+).+/$1/s;
>
>Whoops.  Make that:
>
>$var =~ s/\D.+//s;
>
>I should know better than to think first thing in the morning.  This
>one will also strings that don't start with a number correctly.

Argh.  Replace the + with a * and go on about your life.

JH



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

Date: Wed, 10 Jan 2001 23:56:28 +1100
From: mgjv@tradingpost.com.au (Martien Verbruggen)
Subject: Re: ASCII to integer conversion
Message-Id: <slrn95omvs.u6.mgjv@martien.heliotrope.home>

On Tue, 09 Jan 2001 23:49:20 +0100,
	Clifford Pennock <cliff@*MYLASTNAMEHERE*.nl> wrote:
> 
> Actually, I did. And let me first say that I am very much suprised by
> the incredible patronising that is going on here. Nobody has given the
> original poster a "normal" answer yet. All you guys do is "we are
> Perl-gods and can't be bothered with your petty questions".

What? I thought there was quite some information in this thread. And
even more in the documentatio, which has been referred to quite
extensively.

Oh well, never mind. Some people just are never satisfied.

*plonk*

> That said, I don't think you have read all *my* posts entirely.

I did. But no more.

Martien
-- 
Martien Verbruggen              | 
Interactive Media Division      | I used to have a Heisenbergmobile.
Commercial Dynamics Pty. Ltd.   | Every time I looked at the
NSW, Australia                  | speedometer, I got lost.


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

Date: Thu, 11 Jan 2001 00:06:28 +1100
From: mgjv@tradingpost.com.au (Martien Verbruggen)
Subject: Re: ASCII to integer conversion
Message-Id: <slrn95onik.u6.mgjv@martien.heliotrope.home>

On Wed, 10 Jan 2001 03:00:56 GMT,
	Jeff Helman <jhelman@wsb.com> wrote:
> 
> So you are looking for an integer in a data stream (file, console,
> doesn't matter).  In C, you are correct, if you call atoi() on a
> non-numeric sequence, the program is going to toss an exception and
> die.

\begin[offtopic]{pedantry}

Actually, that isn't true. 

$ cat foo.c
#include <stdio.h>
#include <stdlib.h>

int main (void)
{
    char *numstr1 = "1234m/s";
    char *numstr2 = "stuff 1234m/s";

    int num1 = atoi(numstr1);
    int num2 = atoi(numstr2);

    printf("Got %d and %d\n", num1, num2);

    return 0;
}

$ gcc -ansi -pedantic -W -Wall foo.c
$ ./a.out
Got 1234 and 0

And from the manual page on atoi (and this is the correct behaviour:

       The  atoi()  function  converts the initial portion of the
       string pointed to by nptr to int.  The  behaviour  is  the
       same as

              strtol(nptr, (char **)NULL, 10);

       except that atoi() does not detect errors.

\end{pedantry}

This behaviour is very much like Perl's default conversion behaviour,
except that atoi() doesn't warn. (Even strtol doesn't warn, or anything,
the only error it detects is whether the given string version of the
integer is within range). I wouldn't be at all surprised if Perl
actually used strtol() and strtod() to do most of this work.

Martien
-- 
Martien Verbruggen              | 
Interactive Media Division      | Little girls, like butterflies, need
Commercial Dynamics Pty. Ltd.   | no excuse - Lazarus Long
NSW, Australia                  | 


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

Date: Thu, 11 Jan 2001 00:09:37 +1100
From: mgjv@tradingpost.com.au (Martien Verbruggen)
Subject: Re: ASCII to integer conversion
Message-Id: <slrn95onoh.u6.mgjv@martien.heliotrope.home>

On Wed, 10 Jan 2001 12:01:41 +0100,
	Clifford Pennock <cliff@*MYLASTNAMEHERE*.nl> wrote:
> 
> And that is exactly the point of this thread. How to convert a scalar
> that starts with a numeric sequence followed by a non-numeric sequence
> to the numeric part only. The answer people were giving was: "There's no
> need to.".

That is not the answer that 'people' were giving. I've asked it before,
and will ask it again: Have you actually read the posts?

Don't bother answering me. By the time your reply arrives here, I will
have reloaded my score file. Just stop trolling, read the answers, and
start understanding what the issues are.

> Well excuse me, but there's always a need to.

Yep, and that exact point has been made. And the point has also been
made that you cannot expect Perl to extract a number from the middle of
a string. But for some reason, you seem to be blind to this, and keep
insisting that 'people' have told you the opposite.

READ

Martien
-- 
Martien Verbruggen              | 
Interactive Media Division      | +++ Out of Cheese Error +++ Reinstall
Commercial Dynamics Pty. Ltd.   | Universe and Reboot +++
NSW, Australia                  | 


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

Date: Wed, 10 Jan 2001 14:27:28 +0100
From: "Alan J. Flavell" <flavell@mail.cern.ch>
Subject: Re: ASCII to integer conversion
Message-Id: <Pine.LNX.4.30.0101101423090.12102-100000@lxplus003.cern.ch>

On Wed, 10 Jan 2001, Martien Verbruggen wrote:

> Oh well, never mind. Some people just are never satisfied.

Up till a few months back, I used to anguish over whether I should add
people to the killfile.  Over quite a short period, it seems to have
got so much easier to decide.

> *plonk*

You too?

> > That said, I don't think you have read all *my* posts entirely.
>
> I did.

I didn't.  I baled out earlier, and I'm only reading this because it's
scored-up by being from you  ;-)

cheers



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

Date: Wed, 10 Jan 2001 12:06:43 GMT
From: damian_taylor@my-deja.com
Subject: Re: CGI vs Javascript dropdowns
Message-Id: <93hj8g$i91$1@nnrp1.deja.com>

Thanks Eric.
That's all I wanted to know.

Damian.


Sent via Deja.com
http://www.deja.com/


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

Date: Wed, 10 Jan 2001 06:10:49 GMT
From: rzilavec@tcn.net (Richard Zilavec)
Subject: Re: counting lines in a file
Message-Id: <3a5bfa1d.91498443@news.tcn.net>

On Wed, 10 Jan 2001 03:41:59 GMT, John Galt <ssomneb@my-deja.com>
wrote:

>Try this.  The double if statement could probably be improved with a
>better regex... have fun playing around with it (I'm sure its
>efficiency can be improved).  It seemed to work for
>me, though.
>
>
>
>#!/usr/bin/perl
>$file="filename.txt";
>open FILENAME, $file or die "Cannot open $file for read: $!";
>$count=0             #so that it will return "0" if there are no
    ^^^^^^^
$count = 0;
>                     #relevant lines
>for (<FILENAME>) {
>     chomp;
>     if ($_) {

A line containing spaces would be true, you should strip off leading
and trailing whitespace before testing.

>          if (!/#/){

This means a line containing a # would not be counted, what about:
$tmp = 100; # some comment goes here..

>               $count++;
>          }
>     }
>}
>print "$count/n";


--
 Richard Zilavec
 rzilavec@tcn.net


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

Date: Wed, 10 Jan 2001 06:17:15 GMT
From: "John W. Krahn" <krahnj@acm.org>
Subject: Re: counting lines in a file
Message-Id: <3A5BFF1F.AB51E053@acm.org>

John Galt wrote:
> 
> Try this.  The double if statement could probably be improved with a
> better regex... have fun playing around with it (I'm sure its
> efficiency can be improved).  It seemed to work for
> me, though.
> 
> #!/usr/bin/perl

#!/usr/bin/perl -w
use strict;

> $file="filename.txt";

my $file = 'filename.txt';

> open FILENAME, $file or die "Cannot open $file for read: $!";

The file name is in "$file" and the file handle is in "FILENAME"?

> $count=0             #so that it will return "0" if there are no
>                      #relevant lines

my $count = 0;

> for (<FILENAME>) {

You probably meant 'while (<FILENAME>) {'

>      chomp;
>      if ($_) {

What it the line has the digit 0 on a line by itself or only contains
whitespace?

>           if (!/#/){

This will skip lines like:
print "This is an example of the # character";
and
$x =~ s#^(.+?)\D#$1#;

>                $count++;
>           }
>      }
> }
> print "$count/n";

print "$count\n";

> 
> Enjoy!
Counting errors.

John


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

Date: Wed, 10 Jan 2001 08:34:06 GMT
From: rgarciasuarez@free.fr (Rafael Garcia-Suarez)
Subject: Re: counting lines in a file
Message-Id: <slrn95o7k9.eou.rgarciasuarez@rafael.kazibao.net>

lpj91100@my-deja.com wrote in comp.lang.perl.misc:
> Hi,
> 
> Does anybody have a perl script that counts the
> numbers of lines of a file, excluding blank lines
> and commented lines?

As a one-liner:
  $ perl -nle '$c++if!/^\s*(#.*)?$/;END{print$c}' filename

-- 
# Rafael Garcia-Suarez / http://rgarciasuarez.free.fr/


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

Date: Wed, 10 Jan 2001 05:51:49 -0500
From: tadmc@augustmail.com (Tad McClellan)
Subject: Re: counting lines in a file
Message-Id: <slrn95ofm5.4bc.tadmc@tadmc26.august.net>

lpj91100@my-deja.com <lpj91100@my-deja.com> wrote:
>
>Does anybody have a perl script that counts the
>numbers of lines of a file, 


You are expected to check the Perl FAQ *before* posting to
the Perl newsgroup:

   perldoc -q count

      "How do I count the number of lines in a file?"


>excluding blank lines
>and commented lines?


That would depend entirely on what the syntax for a
"commented line" is. You haven't told us what kind
of data file you are processing, so we cannot know
what comments look like.


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


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

Date: Tue, 09 Jan 2001 23:19:01 -0600
From: Alan Friedman <afried@mediaone.net>
Subject: Finding logged on user
Message-Id: <3A5BF0C5.4E04BB45@mediaone.net>

Is there a way of finding out the username of a person logged into
a UNIX server and running a web based application,  from within
that application?

Thanks,

Alan Friedman




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

Date: Wed, 10 Jan 2001 08:50:14 GMT
From: rgarciasuarez@free.fr (Rafael Garcia-Suarez)
Subject: Re: Finding logged on user
Message-Id: <slrn95o8ih.eqf.rgarciasuarez@rafael.kazibao.net>

Alan Friedman wrote in comp.lang.perl.misc:
> Is there a way of finding out the username of a person logged into
> a UNIX server and running a web based application,  from within
> that application?

If you mean "logged in via HTTP authentification", then the answer is :
in the REMOTE_USER environment variable, as defined by the CGI
protocol. (this has nothing to do with Perl, by the way).

-- 
# Rafael Garcia-Suarez / http://rgarciasuarez.free.fr/


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

Date: Wed, 10 Jan 2001 06:34:15 GMT
From: "Steve D." <ee@jpcvgg.net>
Subject: Frames
Message-Id: <3A5C2BF1.EF6BACEB@jpcvgg.net>

Hi,
I'm new at developing web pages. I just configured and installed
some perl scripts for a message board I'm working on. I want to know
if it's ok to use FrontPage 2000 (not FrontPage's Discussion Web Wizard)
to develop this board using Frames even though I won't be using
FrontPage's extensions on the hosting server. If it's possible, please
let me know how. Thanks,

Steve


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

Date: Wed, 10 Jan 2001 16:58:27 +0800
From: "John" <john@imining.com.tw>
Subject: Got error when following perlxstut
Message-Id: <93h8hs$jb7@netnews.hinet.net>

Hi:

I followed each steps in Example 4 of  document perlxstut.
At last when I executed 'make', I got the following error messages:

mkdir blib
mkdir blib/lib
mkdir blib/arch
mkdir blib/arch/auto
mkdir blib/arch/auto/Mytest2
mkdir blib/lib/auto
mkdir blib/lib/auto/Mytest2
mkdir blib/man3
cp Mytest2.pm blib/lib/Mytest2.pm
AutoSplitting blib/lib/Mytest2.pm (blib/lib/auto/Mytest2)
cd mylib && make LIB="" LIBPERL_A="libperl.a" LINKTYPE="dynamic"
PREFIX="/usr/lo
cal" OPTIMIZE="-O2"
make[1]: Entering directory `/home/john/perl_xs/Mytest2/mylib'
make[1]: *** No rule to make target `libmylib.a', needed by `static'.  Stop.
make[1]: Leaving directory `/home/john/perl_xs/Mytest2/mylib'
make: *** [mylib/libmylib.a] Error 2

Had I missed something?
Thanks in advance.

John Hsieh
john@imining.com.tw




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

Date: Wed, 10 Jan 2001 09:04:35 +0100
From: "Ekkehard Domning" <domning@t-online.de>
Subject: Re: Help this newbie learn please :)
Message-Id: <3A5C1793.23687426@192.168.0.5>

Hello Mike
> #!/usr/bin/perl -w
Remove the -w switch when You dont want that perl print "Warnings".
Of course You should write Programs that will not produce warnings, but
often You use code from other people that runs - but dont have the right
"style".
So I turn on -w if the code is under construction and turn -w off if my
work is done :-)
Best regards
Ekkehard

Mike McPherson wrote:
> Ok first the code.
> =

> #!/usr/bin/perl -w
> # Little snip I created to convert ASCII to Characters and vice-versa.
[snip]
> However when i run $>perl ascii2char.pl alone I get:
> =

> Use of uninitialized value at ascii2char.pl line 5.
> Use of uninitialized value at ascii2char.pl line 10.
> =

> Usage ASCII or CHAR:
> =

> which is ok however I would like to hae it only say "Usage ASCII or CHA=
R: "
> any help from here on greatly appriciated.

-- =

DomIS Internet Solution - Ekkehard Domning
Spahner Str. 11 - D-49751 S=F6gel
Mail: edo@domis.de Internet: http://www.domis.de


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

Date: Wed, 10 Jan 2001 09:53:57 GMT
From: helgi@NOSPAMdecode.is (Helgi Briem)
Subject: Re: Help this newbie learn please :)
Message-Id: <3a5c2f9f.73117928@news.itn.is>

On Wed, 10 Jan 2001 14:22:25 +1000, "Mike McPherson"
<hafateltec@hotmail.com> wrote:

>Ok first the code.
>
>#!/usr/bin/perl -w
># Little snip I created to convert ASCII to Characters and vice-versa.
>$what = (shift @ARGV);
>
<SNIP>
>However when i run
>$>perl ascii2char.pl alone I get:
>
>Use of uninitialized value at ascii2char.pl line 5.
>Use of uninitialized value at ascii2char.pl line 10.
>
>Usage ASCII or CHAR:
>
>which is ok however I would like to hae it only say "Usage ASCII or CHAR: "
>
>any help from here on greatly appriciated.
>
Your problem is that $ARGV[0] AKA $what is not
initialised if there are no command line arguments.

Therefore instead of the final else { die .... }, use
if (not @ARGV) { die "\nUsage ASCII or CHAR\n"; }
as the first line after the hashbang line.  This will
cause the program to abort before it gets to the
uninitialised variable.

I see no reason to add the $! in a usage message
although someone may feel there is.  However, it
is a good habit to get into in general.

Oh, yes and do use strict.

Regards,
Helgi Briem


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

Date: Wed, 10 Jan 2001 10:43:13 +0000
From: Paul Boardman <peb@bms.umist.ac.uk>
Subject: Re: Help this newbie learn please :)
Message-Id: <3A5C3CC1.320E1F63@bms.umist.ac.uk>

Wyzelli wrote:

> if (@ARGV){
>     $what = (shift @ARGV);
> }
> else {
>     die "\nUsage ASCII or CHAR: $!\n";
> }

sorry to be one of those nit pickers, but I think perl's natural
language syntax reads much better.

$what = (shift @ARGV) or die "\nUsage ASCII or CHAR: $!\n";

Paul


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

Date: 10 Jan 2001 08:43:58 -0500
From: Doug Perham <dperham@dperham.eng.tvol.net>
Subject: Re: Help this newbie learn please :)
Message-Id: <81snmr34kh.fsf@wgate.com>

"Mike McPherson" <hafateltec@hotmail.com> writes:

> Ok first the code.
> 
> #!/usr/bin/perl -w
> # Little snip I created to convert ASCII to Characters and vice-versa.
> $what = (shift @ARGV);
>

when you run the script without arguments, "shift @ARGV" returns the
value undef.  thus every time you use $what, you will get that "use of
uninitialized ...".  There are many ways to avoid this, one would be to
move your Usage block toward the top, like 

if ( ! defined($what) ) 
{
  die "\nUsage ASCII or CHAR: $!\n";
}
 
> if ($what eq 'ASCII') {
> print "\nOption ASCII\n";print "\nPlease enter the ASCII Number you wish to
> convert to a character --->";
> $ascii = <STDIN>;
> $convert_ascii = chr($ascii);
> print "\nYour conversion is chr/($ascii) equals $convert_ascii\n";
> } elsif ($what eq 'CHAR') {
> print "\nOption CHAR\n";
> print "\nPlease enter the Character you wish to convert to ASCII --->";
> $char = <STDIN>;
> $convert_char = ord($char);
> print "\nYour conversion is $char equals $convert_char\n";
> }
> else {
> die "\nUsage ASCII or CHAR: $!\n";
> }
> 
> At the command line if I run $>perl ascii2char.pl ASCII or $>perl
> ascii2char.pl CHAR the program works as it should... However when i run
> $>perl ascii2char.pl alone I get:
> 
> Use of uninitialized value at ascii2char.pl line 5.
> Use of uninitialized value at ascii2char.pl line 10.
> 
> Usage ASCII or CHAR:
> 
> which is ok however I would like to hae it only say "Usage ASCII or CHAR: "
> 
> any help from here on greatly appriciated.

-- 
Doug Perham                                          o{..}o     
dperham@wgate.com                                moo! (oo)___   
WorldGate Communications, Inc.                        (______)\ 
                                                      / \  / \  


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

Date: Wed, 10 Jan 2001 05:31:53 GMT
From: eggie@REMOVE_TO_REPLYsunlink.net (James Kufrovich)
Subject: Re: HTML stripper
Message-Id: <slrn95nt46.7b7.eggie@melody.mephit.com>

On Mon, 08 Jan 2001 11:18:45 GMT, simonharris44@my-deja.com
<simonharris44@my-deja.com> wrote:

>Could somebody point me in the direction of a regexp or script to strip
>HTML tags from form submissions (you guessed it - its for a message
>board)

Try something like this:

	if ($message =~ m!<(.*?)>\s*(.*?)\s*</\1>!i) {
		#error!  contains html.  
	}

	That takes care of different cases for the matching HTML tags (if
one is all lower-case and the other is all upper-case, for example), and
having the \s in there will make it match if there's a newline between the
two tags, but only if the newline is right next to the tag, apparently.  
I'm sure this can be improved somehow, though, but I'm far from being an
expert at regexes.

Hope this helps (tm)

Jamie Kufrovich

-- 
Egg, eggie@REMOVE_TO_REPLYsunlink.net
FMSp3a/MS3a A- C D H+ M+ P+++ R+ T W Z+ 
Sp++/p# RLCT a+ cl++ d? e++ f h* i+ j p+ sm+


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

Date: Wed, 10 Jan 2001 13:21:34 -0000
From: "Geoff Winkless" <geoff-at-farmline-dot-com@127.0.0.1>
Subject: Re: Is $? set when using backticks to issue a system command
Message-Id: <93hnie$go2$1@soap.pipex.net>

"Brandon Metcalf" <bmetcalf@nortelnetworks.com> wrote in message
news:93fr6t$sao$1@bcarh8ab.ca.nortel.com...
: brannon@lnc.usc.edu writes:
:
:  > PerlFAQ Server <faq@denver.pm.org> writes:
:  >
:  > >         $exit_status   = system("mail-users");
:  > >         $output_string = `ls`;
:  >
:  > Can I still get return status of the process with $?
:
: Obviously you don't know how to read the manual.  Hmm, let's look in the
: perlvar man page.  Hey, what do you know...

Bear in mind that if you have a signal handler set to catch SIGCHLD $? will
not be set correctly.

Geoff
(please ignore any earlier message like this one, it should be cancelled,
thanks to my typo *sigh*)




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

Date: Wed, 10 Jan 2001 05:41:38 -0500
From: tadmc@augustmail.com (Tad McClellan)
Subject: Re: List Results
Message-Id: <slrn95of32.4bc.tadmc@tadmc26.august.net>

John Hall <jhall@ifxonline.com> wrote:
>
>Thanks to the aid of this list 


This is not a (mailing?) list.

This is a Usenet newsgroup.

Usenet is not email.


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


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

Date: 16 Sep 99 21:33:47 GMT (Last modified)
From: Perl-Users-Request@ruby.oce.orst.edu (Perl-Users-Digest Admin) 
Subject: Digest Administrivia (Last modified: 16 Sep 99)
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.  

| NOTE: The mail to news gateway, and thus the ability to submit articles
| through this service to the newsgroup, has been removed. I do not have
| time to individually vet each article to make sure that someone isn't
| abusing the service, and I no longer have any desire to waste my time
| dealing with the campus admins when some fool complains to them about an
| article that has come through the gateway instead of complaining
| to the source.

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


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