[28935] in Perl-Users-Digest
Perl-Users Digest, Issue: 179 Volume: 11
daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Tue Feb 27 21:09:54 2007
Date: Tue, 27 Feb 2007 18:09:05 -0800 (PST)
From: Perl-Users Digest <Perl-Users-Request@ruby.OCE.ORST.EDU>
To: Perl-Users@ruby.OCE.ORST.EDU (Perl-Users Digest)
Perl-Users Digest Tue, 27 Feb 2007 Volume: 11 Number: 179
Today's topics:
Re: Choosing the path based on the system "uname" comma <wblock@wonkity.com>
Re: Choosing the path based on the system "uname" comma <ben@morrow.me.uk>
Re: Choosing the path based on the system "uname" comma <doni.sekar@gmail.com>
Re: Choosing the path based on the system "uname" comma <hjp-usenet2@hjp.at>
Re: DocumentHTML ? <tadmc@augustmail.com>
Re: DocumentHTML ? <g_m@remove-comcast.net>
Re: Perl threads - capturing value returned from sub anno4000@radom.zrz.tu-berlin.de
Re: Question about scoping <someone@example.com>
sysread & eof <lstouder@teksavvy.com>
Re: updating date field in MS Access <lambik@kieffer.nl>
using a list corefile@gmail.com
Re: using a list <someone@example.com>
Re: using a list <lambik@kieffer.nl>
Re: using a list corefile@gmail.com
Re: using a list <DJStunks@gmail.com>
Digest Administrivia (Last modified: 6 Apr 01) (Perl-Users-Digest Admin)
----------------------------------------------------------------------
Date: Tue, 27 Feb 2007 21:39:58 -0000
From: Warren Block <wblock@wonkity.com>
Subject: Re: Choosing the path based on the system "uname" command
Message-Id: <slrneu999r.o79.wblock@speedy.wonkity.com>
doni <doni.sekar@gmail.com> wrote:
>
> I want to write a program that does check the appropriate system path
> for perl in FreeBSD and Linux.
Why?
> The path where I have it in FreeBSD is
> #! /usr/local/bin/perl
Look for other links:
% which perl
/usr/bin/perl
% uname -smr
FreeBSD 6.2-STABLE i386
If you installed Perl from ports, /usr/bin/perl should be there.
> I wanted the program to check for the uname of the system and choose
> the appropriate path.
Not a good way to check, since it could be anywhere. which or whereis
would be better.
> Can anyone tell me how can I have my program
> check this.
chomp(my $perlpath = `which perl`);
print "path to perl is $perlpath\n";
--
Warren Block * Rapid City, South Dakota * USA
------------------------------
Date: Tue, 27 Feb 2007 22:09:26 +0000
From: Ben Morrow <ben@morrow.me.uk>
Subject: Re: Choosing the path based on the system "uname" command
Message-Id: <mpmeb4-q89.ln1@osiris.mauzo.dyndns.org>
Quoth "doni" <doni.sekar@gmail.com>:
> Hi,
>
> I want to write a program that does check the appropriate system path
> for perl in FreeBSD and Linux.
>
> The path where I have it in FreeBSD is
> #! /usr/local/bin/perl
>
> and the path where it is in Linux is
> #! /usr/bin/perl
>
> I wanted the program to check for the uname of the system and choose
> the appropriate path. Can anyone tell me how can I have my program
> check this.
This is not a Perl question. The path on the #! line is not used by
perl, but by your operating system. In general, there is no way to put
any logic into that line, though
#!/usr/bin/env perl
may do what you want. Note that it will use the perl in your current
PATH, which may be a security risk. As others have said, you are much
better off arranging for perl to be available as /usr/bin/perl, or
writing some sort of installation script that changes the #! line.
Ben
--
For far more marvellous is the truth than any artists of the past imagined!
Why do the poets of the present not speak of it? What men are poets who can
speak of Jupiter if he were like a man, but if he is an immense spinning
sphere of methane and ammonia must be silent? [Feynmann] ben@morrow.me.uk
------------------------------
Date: 27 Feb 2007 14:44:44 -0800
From: "doni" <doni.sekar@gmail.com>
Subject: Re: Choosing the path based on the system "uname" command
Message-Id: <1172616284.228181.159300@t69g2000cwt.googlegroups.com>
On Feb 27, 2:09 pm, Ben Morrow <b...@morrow.me.uk> wrote:
> This is not a Perl question. The path on the #! line is not used by
> perl, but by your operating system. In general, there is no way to put
> any logic into that line, though
>
> #!/usr/bin/env perl
>
> may do what you want. Note that it will use the perl in your current
> PATH, which may be a security risk. As others have said, you are much
> better off arranging for perl to be available as /usr/bin/perl, or
> writing some sort of installation script that changes the #! line.
>
> Ben
Thanks for your input. I will have an installation script to change
the #! line.
Thanks,
doni
------------------------------
Date: Tue, 27 Feb 2007 23:57:49 +0100
From: "Peter J. Holzer" <hjp-usenet2@hjp.at>
Subject: Re: Choosing the path based on the system "uname" command
Message-Id: <slrneu9drd.9rs.hjp-usenet2@yoyo.hjp.at>
On 2007-02-27 22:09, Ben Morrow <ben@morrow.me.uk> wrote:
> Quoth "doni" <doni.sekar@gmail.com>:
[changing the shebang line depending on uname]
> As others have said, you are much better off arranging for perl to be
> available as /usr/bin/perl, or writing some sort of installation
> script that changes the #! line.
If you use ExtUtils::MakeMaker or Module::Build, this is done
automatically at install time.
hp
--
_ | Peter J. Holzer | Es ist ganz einfach ihn zu verstehen, wenn
|_|_) | Sysadmin WSR | man nur alle wichtigen Worte im Satz durch
| | | hjp@hjp.at | andere ersetzt.
__/ | http://www.hjp.at/ | -- Nils Ketelsen in danr
------------------------------
Date: Tue, 27 Feb 2007 18:02:02 -0600
From: Tad McClellan <tadmc@augustmail.com>
Subject: Re: DocumentHTML ?
Message-Id: <slrneu9hjq.490.tadmc@tadmc30.august.net>
~greg <g_m@remove-comcast.net> wrote:
> Gentlemen, I'm old.
Me too. Bummer eh?
> It would never have occurred to me that explicit "use strict"
> and "use warnings" is a courtesy to others.
Please see the Posting Guidelines that are posted here frequently.
> I will do it from now on.
Thank you.
[ snip TOFU.
Please don't do that either.
]
--
Tad McClellan SGML consulting
tadmc@augustmail.com Perl programming
Fort Worth, Texas
------------------------------
Date: Tue, 27 Feb 2007 20:21:30 -0500
From: "~greg" <g_m@remove-comcast.net>
Subject: Re: DocumentHTML ?
Message-Id: <ceidndaqk4ODRHnYnZ2dnUVZ_tqnnZ2d@comcast.com>
> [ snip TOFU.
> Please don't do that either.
> ]
>
> --
> Tad McClellan SGML consulting
> tadmc@augustmail.com Perl programming
> Fort Worth, Texas
please don't spam.
------------------------------
Date: 27 Feb 2007 22:01:01 GMT
From: anno4000@radom.zrz.tu-berlin.de
Subject: Re: Perl threads - capturing value returned from sub
Message-Id: <54jo0tF211275U1@mid.dfncis.de>
Eric <ecarlson@vmware.com> wrote in comp.lang.perl.misc:
> On Feb 26, 5:03 pm, "Eric" <ecarl...@vmware.com> wrote:
> Cancel this one; I found the answer, which was to just assign a
> variable to the join:
>
> my $result = $t->join;
What you really do is, you assign the value of ->join to a variable.
This may sound like nit-picking, but taken literally (not just as
a slip of the fingers) your description would reveal a fundamental
misunderstanding of the meaning of "assign" in this usage.
Anno
------------------------------
Date: Tue, 27 Feb 2007 21:18:02 GMT
From: "John W. Krahn" <someone@example.com>
Subject: Re: Question about scoping
Message-Id: <ee1Fh.690$Xi2.497@edtnps89>
Bob Dubery wrote:
>
> sub validateFile
> {
> # get the value passed to this subroutine
> my $dataString = shift;
>
> # remove the newline character and all other formatting characters
> chomp $dataString;
> $dataString =~ s/\t//g;
> $dataString =~ s/\n//g;
> $dataString =~ s/\r//g;
> $dataString =~ s/\f//g;
OMG! Replace the previous five lines with:
$dataString =~ tr/\t\n\r\f//d;
> # check for and remove the starting charater for the data transfer
> if ($dataString =~ /^/) # character (0x02)
> {
> $dataString =~ s/^//; # character (0x02)
>
> # check for and remove the ending charater for the data transfer
> if ($dataString =~ /$/) # character (0x03)
> {
> $dataString =~ s/$//; # character (0x03)
You don't need to run the same regular expression twice, nor do you really
need the comment:
# check for and remove the starting charater for the data transfer
if ($dataString =~ s/^\x02//)
{
# check for and remove the ending charater for the data transfer
if ($dataString =~ s/\x03$//)
{
John
--
Perl isn't a toolbox, but a small machine shop where you can special-order
certain sorts of tools at low cost and in short order. -- Larry Wall
------------------------------
Date: Tue, 27 Feb 2007 20:17:09 -0500
From: lucas <lstouder@teksavvy.com>
Subject: sysread & eof
Message-Id: <1573f$45e4d810$cef8bf3d$22913@TEKSAVVY.COM-Free>
I'm use IO::Socket on linux to read from a webpage. I don't want to use
LWP::Simple. How would I find the EOF when the web server is finished
sending me the webpage? Here's what I'm using right now:
while (my $res = sysread($sock_in,$buf,$bufsize)) {
syswrite($sock_out,$buf,length($buf));
last if ($res < $bufsize);
}
It works, but obviously, if a webpage has a size that is a multiple of
$bufsize, this will loop forever.
Regards,
--
lucas
-------------------------
Perl Coder since 2001
shift || die;
-------------------------
------------------------------
Date: Tue, 27 Feb 2007 23:25:06 +0100
From: "Lambik" <lambik@kieffer.nl>
Subject: Re: updating date field in MS Access
Message-Id: <45e4af08$0$732$5fc3050@dreader2.news.tiscali.nl>
"kath" <nitte.sudhir@gmail.com> wrote in message
news:1172557813.714277.263660@p10g2000cwp.googlegroups.com...
> hi,
>
> I am having problem in updating tables in MS Access. The field which I
> want to update is of DATE type.
>
> here is the code..
>
> #! C:\Perl\bin\perl.exe
>
> use Win32::ODBC;
>
> my $db = new Win32::ODBC('ServerStatistics');
>
> $q="select distinct(build_date) from wdf_history";
> $db->Sql($q);
> while($db->FetchRow)
> {
> $s = $db->Data();
> print $s;
> }
>
> $q = "select * from wdf_history where build_date='$s'";
>
> while($db->FetchRow)
> {
> $s = $db->Data();
> print $s;
> }
>
> $q="update wdf_history set build_date='2007-02-27' where
> build_date='$s'";
> $db->Sql($q);
Dateformat is wrong. In Access dates need to be enclosed by # (what is the
English phrase for that sign? Hash marks?) and Access stores the dates in
dd-mm-yyyy or mm-dd-yyyy depending on your windows country setting.. So:
$q="update wdf_history set build_date='#27-02-2007#' where ...
or
$q="update wdf_history set build_date='#02-27-2007#' where ...
You should try out what works for you.
Good luck.
------------------------------
Date: 27 Feb 2007 14:12:48 -0800
From: corefile@gmail.com
Subject: using a list
Message-Id: <1172614368.083420.209560@z35g2000cwz.googlegroups.com>
Trying to create a way to create a list of ip's port
-ip = 192.168.100.1 #first ip
-nip = 254 #number of ips
@allports = ("25", "110", "443", "179") #listening ports
-fip = 10.100.100.1 # static ip everything get forwarded to
-fport = 10001 # starting port that @allports will forward to running
on fip
What I need to do is have it output a list of ips, in this case I'm
starting with 192.168.100.1 and ending with 192.168.100.254. And for
each of those ip's I need to associate it with each of the ports in my
@allports list and out put that to a file. so I will look something
like:
192.168.100.1 25 maps to 10.100.100.1 20001
192.168.100.1 110 maps to 10.100.100.1 20002
192.168.100.1 443 maps to 10.100.100.1 20003
192.168.100.1 179 maps to 10.100.100.1 20004
192.168.100.2 25 maps to 10.100.100.1 20005
192.168.100.2 110 maps to 10.100.100.1 20006
192.168.100.2 443 maps to 10.100.100.1 20007
192.168.100.2 179 maps to 10.100.100.1 20008
192.168.100.3 25 maps to 10.100.100.1 20009
....
....
192.168.100.254 179 maps to 10.100.100.1 21016
This is what I have so far;
$ip = 192.168.100.1; #first ip
$nip = 254; #number of ips
@allports = ("25", "110", "443", "179"); #listening ports
$fip = 10.100.100.1; # static ip everything get forwarded to
$fport = 10001; # starting port that @allports will forward to running
on fip
$file = somefile.txt;
for ( 1..$n ) {
$ip =~ s/\.(\d+)$/.$_/;
$fport = $fport++;
open (FD, ">>", $file);
printf (FD "$ip maps to $fip $fport\n");
close (FD);
}
I can't figure out how to implement the @allports part. As I'm a total
noob this is probably not the most efficient way but as long as it
work thats fine for me.
------------------------------
Date: Tue, 27 Feb 2007 22:36:23 GMT
From: "John W. Krahn" <someone@example.com>
Subject: Re: using a list
Message-Id: <Hn2Fh.1070$IE4.226@edtnps82>
corefile@gmail.com wrote:
> Trying to create a way to create a list of ip's port
>
> -ip = 192.168.100.1 #first ip
> -nip = 254 #number of ips
> @allports = ("25", "110", "443", "179") #listening ports
> -fip = 10.100.100.1 # static ip everything get forwarded to
> -fport = 10001 # starting port that @allports will forward to running
> on fip
>
>
> What I need to do is have it output a list of ips, in this case I'm
> starting with 192.168.100.1 and ending with 192.168.100.254. And for
> each of those ip's I need to associate it with each of the ports in my
> @allports list and out put that to a file. so I will look something
> like:
>
> 192.168.100.1 25 maps to 10.100.100.1 20001
> 192.168.100.1 110 maps to 10.100.100.1 20002
> 192.168.100.1 443 maps to 10.100.100.1 20003
> 192.168.100.1 179 maps to 10.100.100.1 20004
> 192.168.100.2 25 maps to 10.100.100.1 20005
> 192.168.100.2 110 maps to 10.100.100.1 20006
> 192.168.100.2 443 maps to 10.100.100.1 20007
> 192.168.100.2 179 maps to 10.100.100.1 20008
> 192.168.100.3 25 maps to 10.100.100.1 20009
> ....
> ....
> 192.168.100.254 179 maps to 10.100.100.1 21016
>
> This is what I have so far;
>
>
> $ip = 192.168.100.1; #first ip
> $nip = 254; #number of ips
> @allports = ("25", "110", "443", "179"); #listening ports
> $fip = 10.100.100.1; # static ip everything get forwarded to
> $fport = 10001; # starting port that @allports will forward to running
> on fip
> $file = somefile.txt;
>
> for ( 1..$n ) {
> $ip =~ s/\.(\d+)$/.$_/;
> $fport = $fport++;
>
> open (FD, ">>", $file);
> printf (FD "$ip maps to $fip $fport\n");
> close (FD);
> }
>
>
> I can't figure out how to implement the @allports part. As I'm a total
> noob this is probably not the most efficient way but as long as it
> work thats fine for me.
#!/usr/bin/perl
use warnings;
use strict;
use Socket;
my $ip = unpack 'N', inet_aton '192.168.100.1'; #first ip
my $number = 254; #number of ips
my @allports = ( 25, 110, 443, 179 ); #listening ports
my $forward = '10.100.100.1'; # static ip everything get forwarded to
my $fport = 10001; # starting port that @allports will
# forward to running on fip
my $file = 'somefile.txt';
open my $FD, '>>', $file or die "Cannot open '$file' $!";
for ( 1 .. $number ) {
my $addr = inet_ntoa pack 'N', $ip;
for my $port ( @allports ) {
print $FD "$addr $port maps to $forward $fport\n";
++$fport;
}
++$ip;
}
close $FD;
__END__
John
--
Perl isn't a toolbox, but a small machine shop where you can special-order
certain sorts of tools at low cost and in short order. -- Larry Wall
------------------------------
Date: Tue, 27 Feb 2007 23:47:18 +0100
From: "Lambik" <lambik@kieffer.nl>
Subject: Re: using a list
Message-Id: <45e4b43c$0$724$5fc3050@dreader2.news.tiscali.nl>
<corefile@gmail.com> wrote in message
news:1172614368.083420.209560@z35g2000cwz.googlegroups.com...
> Trying to create a way to create a list of ip's port
Does this code even run?
> $ip = 192.168.100.1; #first ip
I have no idea what this does. I guess you want "192.168.100.1"
> $nip = 254; #number of ips
Why this? It isn't used
> @allports = ("25", "110", "443", "179"); #listening ports
> $fip = 10.100.100.1; # static ip everything get forwarded to
Same here.
> $fport = 10001; # starting port that @allports will forward to running
> on fip
> $file = somefile.txt;
>
> for ( 1..$n ) {
What's $n? Where is it declared.
> $ip =~ s/\.(\d+)$/.$_/;
> $fport = $fport++;
>
> open (FD, ">>", $file);
> printf (FD "$ip maps to $fip $fport\n");
> close (FD);
> }
>
>
> I can't figure out how to implement the @allports part. As I'm a total
> noob this is probably not the most efficient way but as long as it
> work thats fine for me.
Does it? This code runs? Wow.
If I understand you correctly you want something like:
#!/usr/bin/perl
use warnings;
use strict;
my $ip = "192.168.100"; #first ip
my @allports = ("25", "110", "443", "179"); #listening ports
my $fip = "10.100.100.1"; # static ip everything get forwarded to
my $fport = 10001; # starting port that @allports will forward to running on
fip
my $file = "somefile.txt";
foreach my $port (@allports) {
open (FD, ">>", $file);
print FD "$ip.$port maps to $fip $fport\n";
close (FD);
$fport++;
}
------------------------------
Date: 27 Feb 2007 15:40:20 -0800
From: corefile@gmail.com
Subject: Re: using a list
Message-Id: <1172619620.590614.194660@a75g2000cwd.googlegroups.com>
On Feb 27, 2:36 pm, "John W. Krahn" <some...@example.com> wrote:
> coref...@gmail.com wrote:
> > Trying to create a way to create a list of ip's port
>
> > -ip = 192.168.100.1 #first ip
> > -nip = 254 #number of ips
> > @allports = ("25", "110", "443", "179") #listening ports
> > -fip = 10.100.100.1 # static ip everything get forwarded to
> > -fport = 10001 # starting port that @allports will forward to running
> > on fip
>
> > What I need to do is have it output a list of ips, in this case I'm
> > starting with 192.168.100.1 and ending with 192.168.100.254. And for
> > each of those ip's I need to associate it with each of the ports in my
> > @allports list and out put that to a file. so I will look something
> > like:
>
> > 192.168.100.1 25 maps to 10.100.100.1 20001
> > 192.168.100.1 110 maps to 10.100.100.1 20002
> > 192.168.100.1 443 maps to 10.100.100.1 20003
> > 192.168.100.1 179 maps to 10.100.100.1 20004
> > 192.168.100.2 25 maps to 10.100.100.1 20005
> > 192.168.100.2 110 maps to 10.100.100.1 20006
> > 192.168.100.2 443 maps to 10.100.100.1 20007
> > 192.168.100.2 179 maps to 10.100.100.1 20008
> > 192.168.100.3 25 maps to 10.100.100.1 20009
> > ....
> > ....
> > 192.168.100.254 179 maps to 10.100.100.1 21016
>
> > This is what I have so far;
>
> > $ip = 192.168.100.1; #first ip
> > $nip = 254; #number of ips
> > @allports = ("25", "110", "443", "179"); #listening ports
> > $fip = 10.100.100.1; # static ip everything get forwarded to
> > $fport = 10001; # starting port that @allports will forward to running
> > on fip
> > $file = somefile.txt;
>
> > for ( 1..$n ) {
> > $ip =~ s/\.(\d+)$/.$_/;
> > $fport = $fport++;
>
> > open (FD, ">>", $file);
> > printf (FD "$ip maps to $fip $fport\n");
> > close (FD);
> > }
>
> > I can't figure out how to implement the @allports part. As I'm a total
> > noob this is probably not the most efficient way but as long as it
> > work thats fine for me.
>
> #!/usr/bin/perl
> use warnings;
> use strict;
> use Socket;
>
> my $ip = unpack 'N', inet_aton '192.168.100.1'; #first ip
> my $number = 254; #number of ips
> my @allports = ( 25, 110, 443, 179 ); #listening ports
> my $forward = '10.100.100.1'; # static ip everything get forwarded to
> my $fport = 10001; # starting port that @allports will
> # forward to running on fip
> my $file = 'somefile.txt';
>
> open my $FD, '>>', $file or die "Cannot open '$file' $!";
>
> for ( 1 .. $number ) {
> my $addr = inet_ntoa pack 'N', $ip;
> for my $port ( @allports ) {
> print $FD "$addr $port maps to $forward $fport\n";
> ++$fport;
> }
> ++$ip;
> }
>
> close $FD;
>
> __END__
>
> John
> --
> Perl isn't a toolbox, but a small machine shop where you can special-order
> certain sorts of tools at low cost and in short order. -- Larry Wall
perfect that worked great, one thing I forgot. I need to also have a
variable that takes the date command and makes a name for it.
I need to use the month/date/time/year + a incrementing number, so
building on what we have:
rule 022715362007_1 192.168.100.1 25 maps to 10.100.100.1 20001
rule 022715362007_2 192.168.100.1 110 maps to 10.100.100.1 20002
rule 022715362007_3 192.168.100.1 443 maps to 10.100.100.1 20003
rule 022715362007_4 192.168.100.1 179 maps to 10.100.100.1 20004
rule 022715362007_5 192.168.100.2 25 maps to 10.100.100.1 20005
rule 022715362007_6 192.168.100.2 110 maps to 10.100.100.1 20006
rule 022715362007_7 192.168.100.2 443 maps to 10.100.100.1 20007
rule 022715362007_8 192.168.100.2 179 maps to 10.100.100.1 20008
rule 022715362007_9 192.168.100.3 25 maps to 10.100.100.1 20009
------------------------------
Date: 27 Feb 2007 18:00:05 -0800
From: "DJ Stunks" <DJStunks@gmail.com>
Subject: Re: using a list
Message-Id: <1172628005.234735.230880@m58g2000cwm.googlegroups.com>
On Feb 27, 4:40 pm, coref...@gmail.com wrote:
> On Feb 27, 2:36 pm, "John W. Krahn" <some...@example.com> wrote:
>
>
>
>
>
> > coref...@gmail.com wrote:
> > > Trying to create a way to create a list of ip's port
>
> > > -ip = 192.168.100.1 #first ip
> > > -nip = 254 #number of ips
> > > @allports = ("25", "110", "443", "179") #listening ports
> > > -fip = 10.100.100.1 # static ip everything get forwarded to
> > > -fport = 10001 # starting port that @allports will forward to running
> > > on fip
>
> > > What I need to do is have it output a list of ips, in this case I'm
> > > starting with 192.168.100.1 and ending with 192.168.100.254. And for
> > > each of those ip's I need to associate it with each of the ports in my
> > > @allports list and out put that to a file. so I will look something
> > > like:
>
> > > 192.168.100.1 25 maps to 10.100.100.1 20001
> > > 192.168.100.1 110 maps to 10.100.100.1 20002
> > > 192.168.100.1 443 maps to 10.100.100.1 20003
> > > 192.168.100.1 179 maps to 10.100.100.1 20004
> > > 192.168.100.2 25 maps to 10.100.100.1 20005
> > > 192.168.100.2 110 maps to 10.100.100.1 20006
> > > 192.168.100.2 443 maps to 10.100.100.1 20007
> > > 192.168.100.2 179 maps to 10.100.100.1 20008
> > > 192.168.100.3 25 maps to 10.100.100.1 20009
> > > ....
> > > ....
> > > 192.168.100.254 179 maps to 10.100.100.1 21016
>
> > > This is what I have so far;
>
> > > $ip = 192.168.100.1; #first ip
> > > $nip = 254; #number of ips
> > > @allports = ("25", "110", "443", "179"); #listening ports
> > > $fip = 10.100.100.1; # static ip everything get forwarded to
> > > $fport = 10001; # starting port that @allports will forward to running
> > > on fip
> > > $file = somefile.txt;
>
> > > for ( 1..$n ) {
> > > $ip =~ s/\.(\d+)$/.$_/;
> > > $fport = $fport++;
>
> > > open (FD, ">>", $file);
> > > printf (FD "$ip maps to $fip $fport\n");
> > > close (FD);
> > > }
>
> > > I can't figure out how to implement the @allports part. As I'm a total
> > > noob this is probably not the most efficient way but as long as it
> > > work thats fine for me.
>
> > #!/usr/bin/perl
> > use warnings;
> > use strict;
> > use Socket;
>
> > my $ip = unpack 'N', inet_aton '192.168.100.1'; #first ip
> > my $number = 254; #number of ips
> > my @allports = ( 25, 110, 443, 179 ); #listening ports
> > my $forward = '10.100.100.1'; # static ip everything get forwarded to
> > my $fport = 10001; # starting port that @allports will
> > # forward to running on fip
> > my $file = 'somefile.txt';
>
> > open my $FD, '>>', $file or die "Cannot open '$file' $!";
>
> > for ( 1 .. $number ) {
> > my $addr = inet_ntoa pack 'N', $ip;
> > for my $port ( @allports ) {
> > print $FD "$addr $port maps to $forward $fport\n";
> > ++$fport;
> > }
> > ++$ip;
> > }
>
> > close $FD;
>
> > __END__
>
> > John
> > --
> > Perl isn't a toolbox, but a small machine shop where you can special-order
> > certain sorts of tools at low cost and in short order. -- Larry Wall
>
> perfect that worked great, one thing I forgot. I need to also have a
> variable that takes the date command and makes a name for it.
> I need to use the month/date/time/year + a incrementing number, so
> building on what we have:
>
> rule 022715362007_1 192.168.100.1 25 maps to 10.100.100.1 20001
> rule 022715362007_2 192.168.100.1 110 maps to 10.100.100.1 20002
> rule 022715362007_3 192.168.100.1 443 maps to 10.100.100.1 20003
> rule 022715362007_4 192.168.100.1 179 maps to 10.100.100.1 20004
> rule 022715362007_5 192.168.100.2 25 maps to 10.100.100.1 20005
> rule 022715362007_6 192.168.100.2 110 maps to 10.100.100.1 20006
> rule 022715362007_7 192.168.100.2 443 maps to 10.100.100.1 20007
> rule 022715362007_8 192.168.100.2 179 maps to 10.100.100.1 20008
> rule 022715362007_9 192.168.100.3 25 maps to 10.100.100.1 20009
I suspect you will have no problems modifying John's compact and
straightforward script to accomplish this simple modification. I
would probably use POSIX's strftime to create your datetime string
(see `perldoc POSIX` for details).
Incidentally, I would also make your output much less chatty so that
it would be more portable - a tab or comma separated table would be
more forward-looking IMO.
-jp
------------------------------
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 V11 Issue 179
**************************************