[25987] in Perl-Users-Digest

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

Perl-Users Digest, Issue: 8206 Volume: 10

daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Mon Jun 27 14:05:41 2005

Date: Mon, 27 Jun 2005 11:05:05 -0700 (PDT)
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, 27 Jun 2005     Volume: 10 Number: 8206

Today's topics:
    Re: Checking IP addresses against lists of IPs, partial axel@white-eagle.invalid.uk
        perl script <>
    Re: perl script <lynn.watts@ugs.com>
    Re: perl script <>
    Re: perl script <>
    Re: perl script <nobull@mail.com>
    Re: perl script <keeling@spots.ab.ca>
    Re: perl script <>
    Re: Simple Structure Question <newsAT@screenlightDOT.com>
    Re: Simple Structure Question <noreply@gunnar.cc>
        Digest Administrivia (Last modified: 6 Apr 01) (Perl-Users-Digest Admin)

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

Date: Mon, 27 Jun 2005 13:06:33 GMT
From: axel@white-eagle.invalid.uk
Subject: Re: Checking IP addresses against lists of IPs, partial IPs, and netmasks.
Message-Id: <tRSve.6339$G2.4423@fe1.news.blueyonder.co.uk>

Adam Funk <a24061@yahoo.com> wrote:
> I'm trying to write some Perl code to check an IP addresses against a list
> of strings containing IP address, partial IP addresses ending in ".",
> net/mask pairs and net/masklength pairs.  
 
> In other words, I'd like ip_found("192.168.2.3") to return true if the test
> list contains any of the following:
> 192.168.2.3
> 192.168.
> 192.168.2.0/255.255.255.0
> 192.168.2.0/24
 
Unless I am being very stupid here, what you want to do is simply
match '^192.168.' against the list. So a basic check could be:

    my @list = qw(192.168.2.3
	192.168.
	192.168.2.0/255.255.255.0
	192.168.2.0/24);
    my $instr = '192.168.';
    if (grep /^$instr/, @list) { print "OK"}

However I suspect you are wanting to do more than that and check
if the IP address is within a certain range... but then you would
need to supply more information about the address to be checked
(i.e. what class of address).

Axel


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

Date: Mon, 27 Jun 2005 10:12:00 -0400
From: yo <>
Subject: perl script
Message-Id: <u820c1dgd0rbar9e6e45abdb9ad8bli7ga@4ax.com>

I have a billing program that generates dynamic files in
/usr/private/platypusd/config_files/pms.1234, where 12345 is a random
number and never the same twice.

This file contains some date separated by the pipe sign. Example:

username|password.

I have a perl script that is called by this billing program to parse
the file pms.random# from the directory above. The perl script is as
follows.

#!/usr/bin/perl
open(INFILE, "@ARGV[0]");
        $infile = <INFILE>;
        ($username,$password) = split(/\|/, $infile);
close(INFILE);

@calladduser = ("/usr/sbin/adduser -g 100 -d /home/sites/home/
$password -s /sbin/nologin $username","\n");
system("@calladduser");

print ("New User $username has been successfully added!\n");
print ("New User password: $password\n");
print ("New User Home Directory: /home/sites/home/$username\n");

open(OUTFILE,
">>/usr/local/private/platypusd/secure_dir/plat_adduser.log");
        print OUTFILE ("@calladduser");
close(OUTFILE);

I get an error of not such file or directory when the billing program
calls this script to parse the file. I don't understand much about
perl and I think the script is not looking for the file, maybe it
doesn't know where the file to be parse is. I get an error of No such
file or directory.

I would appreciate if someone could help me on this. Thanks in
advance.

paul


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

Date: Mon, 27 Jun 2005 07:34:43 -0700
From: "lynn" <lynn.watts@ugs.com>
Subject: Re: perl script
Message-Id: <42c00cd8$1@usenet.ugs.com>

Hello paul,

yo wrote:
> I have a billing program that generates dynamic files in
> /usr/private/platypusd/config_files/pms.1234, where 12345 is a random
> number and never the same twice.
(snipped)

> #!/usr/bin/perl
use strict;
use warnings;

These two lines need to be added to help you troubleshoot the problem.

> open(INFILE, "@ARGV[0]");
                            ^^^^^^^^^^^

I don't think that is right. Should'nt that be $ARGV[0] also
you need to check to see if that worked
like:

open (INFILE, "$ARGV[0]") or die "Can't open file $ARGV[0] $!\n"

>        $infile = <INFILE>;
>        ($username,$password) = split(/\|/, $infile);
> close(INFILE);
>
> @calladduser = ("/usr/sbin/adduser -g 100 -d /home/sites/home/
> $password -s /sbin/nologin $username","\n");
> system("@calladduser");

Same here check to see if the command ran correctly!

system ("@calladduser") or die " call to add user failed $!\n"

>
> print ("New User $username has been successfully added!\n");
> print ("New User password: $password\n");
> print ("New User Home Directory: /home/sites/home/$username\n");
>
> open(OUTFILE,
> ">>/usr/local/private/platypusd/secure_dir/plat_adduser.log");
>        print OUTFILE ("@calladduser");

Same here!

> close(OUTFILE);
same here!
>
lynn 




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

Date: Mon, 27 Jun 2005 10:46:21 -0400
From: yo <>
Subject: Re: perl script
Message-Id: <6940c1l5trgp4nsi6re0408vsk3i2kcdkd@4ax.com>


I will try this right now lynn, thanks 


On Mon, 27 Jun 2005 07:34:43 -0700, "lynn" <lynn.watts@ugs.com> wrote:

>Hello paul,
>
>yo wrote:
>> I have a billing program that generates dynamic files in
>> /usr/private/platypusd/config_files/pms.1234, where 12345 is a random
>> number and never the same twice.
>(snipped)
>
>> #!/usr/bin/perl
>use strict;
>use warnings;
>
>These two lines need to be added to help you troubleshoot the problem.
>
>> open(INFILE, "@ARGV[0]");
>                            ^^^^^^^^^^^
>
>I don't think that is right. Should'nt that be $ARGV[0] also
>you need to check to see if that worked
>like:
>
>open (INFILE, "$ARGV[0]") or die "Can't open file $ARGV[0] $!\n"
>
>>        $infile = <INFILE>;
>>        ($username,$password) = split(/\|/, $infile);
>> close(INFILE);
>>
>> @calladduser = ("/usr/sbin/adduser -g 100 -d /home/sites/home/
>> $password -s /sbin/nologin $username","\n");
>> system("@calladduser");
>
>Same here check to see if the command ran correctly!
>
>system ("@calladduser") or die " call to add user failed $!\n"
>
>>
>> print ("New User $username has been successfully added!\n");
>> print ("New User password: $password\n");
>> print ("New User Home Directory: /home/sites/home/$username\n");
>>
>> open(OUTFILE,
>> ">>/usr/local/private/platypusd/secure_dir/plat_adduser.log");
>>        print OUTFILE ("@calladduser");
>
>Same here!
>
>> close(OUTFILE);
>same here!
>>
>lynn 
>



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

Date: Mon, 27 Jun 2005 11:04:54 -0400
From: yo <>
Subject: Re: perl script
Message-Id: <8a50c1t1h7hm3s0r0b9k6t9mb00gcqhbup@4ax.com>


I got some error using those commands any idea why the following is
happening

[root@test secure_dir]# ./plat_adduser
bash: ./plat_adduser: No such file or directory


[root@test secure_dir]# perl plat_adduser
usage: adduser  [-u uid [-o]] [-g group] [-G group,...]
                [-d home] [-s shell] [-c comment] [-m [-k template]]
                [-f inactive] [-e expire mm/dd/yy] [-p passwd] [-n]
[-r] name
       adduser  -D [-g group] [-b base] [-s shell] [-f inactive] [-e
expire mm/dd/yy]
New User  has been successfully added!
New User password:
New User Home Directory: /home/sites/home/


whats the difference between ./ and using perl to execute a perl
script. ./ isnt working.


On Mon, 27 Jun 2005 10:46:21 -0400, yo <> wrote:

>
>I will try this right now lynn, thanks 
>
>
>On Mon, 27 Jun 2005 07:34:43 -0700, "lynn" <lynn.watts@ugs.com> wrote:
>
>>Hello paul,
>>
>>yo wrote:
>>> I have a billing program that generates dynamic files in
>>> /usr/private/platypusd/config_files/pms.1234, where 12345 is a random
>>> number and never the same twice.
>>(snipped)
>>
>>> #!/usr/bin/perl
>>use strict;
>>use warnings;
>>
>>These two lines need to be added to help you troubleshoot the problem.
>>
>>> open(INFILE, "@ARGV[0]");
>>                            ^^^^^^^^^^^
>>
>>I don't think that is right. Should'nt that be $ARGV[0] also
>>you need to check to see if that worked
>>like:
>>
>>open (INFILE, "$ARGV[0]") or die "Can't open file $ARGV[0] $!\n"
>>
>>>        $infile = <INFILE>;
>>>        ($username,$password) = split(/\|/, $infile);
>>> close(INFILE);
>>>
>>> @calladduser = ("/usr/sbin/adduser -g 100 -d /home/sites/home/
>>> $password -s /sbin/nologin $username","\n");
>>> system("@calladduser");
>>
>>Same here check to see if the command ran correctly!
>>
>>system ("@calladduser") or die " call to add user failed $!\n"
>>
>>>
>>> print ("New User $username has been successfully added!\n");
>>> print ("New User password: $password\n");
>>> print ("New User Home Directory: /home/sites/home/$username\n");
>>>
>>> open(OUTFILE,
>>> ">>/usr/local/private/platypusd/secure_dir/plat_adduser.log");
>>>        print OUTFILE ("@calladduser");
>>
>>Same here!
>>
>>> close(OUTFILE);
>>same here!
>>>
>>lynn 
>>



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

Date: Mon, 27 Jun 2005 17:46:43 +0100
From: Brian McCauley <nobull@mail.com>
Subject: Re: perl script
Message-Id: <d9pahp$res$1@redhat2.bham.ac.uk>

yo wrote:

> I got some error using those commands

What commands?  Please place your responses in context.

> any idea why the following is happening
> 
> [root@test secure_dir]# ./plat_adduser
> bash: ./plat_adduser: No such file or directory

> [root@test secure_dir]# perl plat_adduser
(not an error)

> whats the difference between ./ and using perl to execute a perl
> script. ./ isnt working.

Just executing the script will look for the interpreter in the location 
specified in shebang line (#!).

Specifiying 'perl' will look for program 'perl' in the directories 
listed in the evironment variable PATH.

>>>>#!/usr/bin/perl

So either perl is installed soemwhere other than /usr/bin or there's an 
invisible character on the end of that line.



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

Date: Mon, 27 Jun 2005 16:52:12 GMT
From: "s. keeling" <keeling@spots.ab.ca>
Subject: Re: perl script
Message-Id: <slrndc0blr.g69.keeling@localhost.localdomain>

yo <>:
> 
> [snip]
>  [root@test secure_dir]# perl plat_adduser
>  usage: adduser  [-u uid [-o]] [-g group] [-G group,...]
>                  [-d home] [-s shell] [-c comment] [-m [-k template]]
>                  [-f inactive] [-e expire mm/dd/yy] [-p passwd] [-n]
>  [-r] name
>         adduser  -D [-g group] [-b base] [-s shell] [-f inactive] [-e
>  expire mm/dd/yy]
>  New User  has been successfully added!

Bizarre.  man adduser.

>  whats the difference between ./ and using perl to execute a perl
>  script. ./ isnt working.

Likely you haven't turned on execute bits on the file.  "ls -l
plat_adduser" should show something like:

   -rw-r--r--    ...

meaning it's not excutable (and that's off-topic).  man chmod (eg.,
"chmod 744 plat_adduser" or "chmod u+x plat_adduser").


-- 
    Any technology distinguishable from magic is insufficiently advanced.
    (*)    http://www.spots.ab.ca/~keeling           Linux Counter #80292
    - -    Spammers! http://www.spots.ab.ca/~keeling/autospam.html
http://www.ietf.org/rfc/rfc1855.txt democracy human rights Taiwan Independence


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

Date: Mon, 27 Jun 2005 13:53:32 -0400
From: yo <>
Subject: Re: perl script
Message-Id: <i7f0c1l7411sbfhfjpeppcvf22prgs9lrj@4ax.com>

weird once i copied the contents of that script to a new file it
started working with ./ and using perl on the command line. thanks for
all the help.

On Mon, 27 Jun 2005 10:12:00 -0400, yo <> wrote:

>I have a billing program that generates dynamic files in
>/usr/private/platypusd/config_files/pms.1234, where 12345 is a random
>number and never the same twice.
>
>This file contains some date separated by the pipe sign. Example:
>
>username|password.
>
>I have a perl script that is called by this billing program to parse
>the file pms.random# from the directory above. The perl script is as
>follows.
>
>#!/usr/bin/perl
>open(INFILE, "@ARGV[0]");
>        $infile = <INFILE>;
>        ($username,$password) = split(/\|/, $infile);
>close(INFILE);
>
>@calladduser = ("/usr/sbin/adduser -g 100 -d /home/sites/home/
>$password -s /sbin/nologin $username","\n");
>system("@calladduser");
>
>print ("New User $username has been successfully added!\n");
>print ("New User password: $password\n");
>print ("New User Home Directory: /home/sites/home/$username\n");
>
>open(OUTFILE,
>">>/usr/local/private/platypusd/secure_dir/plat_adduser.log");
>        print OUTFILE ("@calladduser");
>close(OUTFILE);
>
>I get an error of not such file or directory when the billing program
>calls this script to parse the file. I don't understand much about
>perl and I think the script is not looking for the file, maybe it
>doesn't know where the file to be parse is. I get an error of No such
>file or directory.
>
>I would appreciate if someone could help me on this. Thanks in
>advance.
>
>paul



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

Date: Mon, 27 Jun 2005 17:16:59 GMT
From: one man army <newsAT@screenlightDOT.com>
Subject: Re: Simple Structure Question
Message-Id: <newsAT-E7DA7A.10160027062005@newssvr13-ext.news.prodigy.com>

You know why All Five of you men are so cool, because You Read The 
Manual! All 800+ pages of gnarly, dense, encoded hard-core Perl. You 
have worked so hard at reading the manual, that you cannot wait to leap 
out, virutally in unison, with a shouts of "Read the Manual!"

I admit it, after 2 straight 15 hour plus research days, on a completely 
unrelated topic, I though I could get a Perl program running to just 
read the contents of 840 links on a web page. I read the manual, I went 
to CPAN, I installed the module, and it worked! That's why you guys are 
worth it, 'cause your language does work.

But in the Beginners Perl Book I have, there is no discussion of this 
terse syntax I encountered, so yes, I asked for someone to help and 
explain it. It was weak, there were _more manuals_ I could have read 
first.

The post that is really the indicator of them all I think is Tassilo's 
with the .sig that says "use bigint;
$n=71423350343770280161397026330337371139054411854220053437565440;
$m=-8,;;$_=$n&(0xff)<<$m,,$_>>=$m,,print+chr,,while(($m+=8)<=200);"

I have worked as a C programmer for 15 years. I have written and shipped 
and rev'ed huge commercial applications. You will never, ever, ever find 
code like that in any file, ever. It is considered Bad Practice, for 
good reasons. 

This Perl group is absolutely reflective of the traditional UNIX 
culture, dense, terse, sup smart CRYPTO code. If you can't read it, what 
are you doing here - you have manuals to read!!

I am going to have a look at arrays of hashes actually, because I really 
do want to be able to read this web page. I got a good day/night of 
rest. But I don't have months to just study Perl. So I thought if 
someone wanted to try to explain the construct, they could. The post was 
hasty, I admit it. Thank you for the DataDumper pointer. I am used to a 
header file with a struct definition, but I am not there in Perl.


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

Date: Mon, 27 Jun 2005 19:43:28 +0200
From: Gunnar Hjalmarsson <noreply@gunnar.cc>
Subject: Re: Simple Structure Question
Message-Id: <3ias63Fkm2e9U1@individual.net>

one man army wrote:
> I am going to have a look at arrays of hashes actually, because I really 
> do want to be able to read this web page. I got a good day/night of 
> rest.

Good. :)

> But I don't have months to just study Perl. So I thought if 
> someone wanted to try to explain the construct, they could.

To understand the construct, you need to understand the concept of 
nested data structures in Perl, and nobody will explain that concept 
better than perldoc in a reply to your post.

-- 
Gunnar Hjalmarsson
Email: http://www.gunnar.cc/cgi-bin/contact.pl


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

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.  

NOTE: due to the current flood of worm email banging on ruby, the smtp
server on ruby has been shut off until further notice. 

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


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