[25732] in Perl-Users-Digest
Perl-Users Digest, Issue: 7972 Volume: 10
daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Wed Apr 13 18:05:29 2005
Date: Wed, 13 Apr 2005 15:05:12 -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 Wed, 13 Apr 2005 Volume: 10 Number: 7972
Today's topics:
Re: Angle Brackets vs. foreach <tzz@lifelogs.com>
Re: can anyone explain the last two lines to me?thanks! <pilkowsk@informatik.uni-marburg.de>
Re: can anyone explain the last two lines to me?thanks! biomahui@gmail.com
Re: Comparing Regular Expressions (Mark Jason Dominus)
help understanding ++ <hendrik_maryns@despammed.com>
Re: help understanding ++ <ddunham@redwood.taos.com>
Re: help understanding ++ <hendrik_maryns@despammed.com>
How to reverse the time localtime/gmtime function's pro <ljames@apollo3.com>
Re: How to reverse the time localtime/gmtime function's <pilkowsk@informatik.uni-marburg.de>
Re: How to reverse the time localtime/gmtime function's <1usa@llenroc.ude.invalid>
Re: How to reverse the time localtime/gmtime function's <mothra@nowhereatall.com>
how to run perl script from a perl script? anywherenotes@gmail.com
Re: how to run perl script from a perl script? xhoster@gmail.com
Re: how to run perl script from a perl script? <pilsl@goldfisch.at>
Re: how to run perl script from a perl script? anywherenotes@gmail.com
Re: Is Perl open source? <comdog@panix.com>
is there a minimal LDAP server written in Perl? <tzz@lifelogs.com>
Re: LWP::UserAgent and basic authentication <no@email.com>
Re: Matching mixed up words <usenet@vyznev.invalid>
Net::Telnet in a foreach loop <assegai@planet.nl>
Net::Telnet prompt problem colintelfer@hotmail.com
suggestion for perlop <hendrik_maryns@despammed.com>
Re: Web Interface and index.pl separated?!? <hackeras@gmail.com>
Re: Web Interface and index.pl separated?!? <glex_nospam@qwest.invalid>
Re: Web Interface and index.pl separated?!? <hackeras@gmail.com>
Digest Administrivia (Last modified: 6 Apr 01) (Perl-Users-Digest Admin)
----------------------------------------------------------------------
Date: Wed, 13 Apr 2005 14:18:38 -0400
From: Ted Zlatanov <tzz@lifelogs.com>
Subject: Re: Angle Brackets vs. foreach
Message-Id: <4npswy5ym9.fsf@lifelogs.com>
On 13 Apr 2005, Nathan.Neff@gmail.com wrote:
> I recently encountered a performance problem which was fixed by
> changing:
>
> while($file = <@files>)
>
> to
>
> foreach $file(@files)
>
> Can anyone explain the reason for the performance hit? My program took
> 3 minutes using the <> operator, vs. about 2 seconds using foreach.
>
> I realize that the angle brackets operator <> is not really for list
> iteration. But when you evaluate it in scalar context, it does return
> the contents of the list, one by one.
It does, but only after passing them through the glob() function.
This is what slows you down. It does make sense sometimes, if you
expect wildcards in your file names and want to make sure they get
expanded.
Look at "perldoc -f glob" and go from there.
Ted
----== Posted via Newsfeeds.Com - Unlimited-Uncensored-Secure Usenet News==----
http://www.newsfeeds.com The #1 Newsgroup Service in the World! 120,000+ Newsgroups
----= East and West-Coast Server Farms - Total Privacy via Encryption =----
------------------------------
Date: Wed, 13 Apr 2005 20:27:58 +0200
From: Fabian Pilkowski <pilkowsk@informatik.uni-marburg.de>
Subject: Re: can anyone explain the last two lines to me?thanks!
Message-Id: <3c56jhF6i2gn9U1@individual.net>
* biomahui@gmail.com schrieb:
> #!/usr/bin/perl
> $_='OTcommailDngATghiliaguans';
> 1 while s/(.{5})(.{5})?/$_{$2}=$1,$2/e;
> print while $_=$_{$_};
It's unusual to put all your text into the posting's subject. It is
possible to ask your question in the posting's body next time? ;-)
Nevertheless, "you" are looking for the first two parts of $_, each 5
chars long. With »$_{$2}=$1« these two parts becomes a key-value-pair in
the hash »%_«. Then you substitutes these two parts with the second one,
i.e. you simply deletes the first 5 chars of $_. That's all your loop is
doing, but successively until your string $_ is shorter than 5 chars. In
your example above this first while loop will give you the hash
%_ = (
'mailD' => 'OTcom',
'ngATg' => 'mailD',
'hilia' => 'ngATg',
'guans' => 'hilia'
'' => 'guans'
);
Now, the string $_ is empty. The second while loop takes the element $_
of %_ and assigns its value to $_ again. So its first pass gets $_{''}
so that $_ contains 'guans' afterwards. print() without params will
print out the content of $_. The next pass is looking for the hash
element 'guans', so it returns 'hilia', etc. Hence, the following
strings arrives one after the other your console:
guans
hilia
ngATg
mailD
OTcom
Reading this as one line could be interpreted as a mailaddress. Btw,
next time you could change your code to
$_='OTcommailDngATghiliaguans';
print "\$_{'$2'}='$1' --> \$_ = '$_'\n" while s/(.{5})(.{5})?/$_{$2}=$1,$2/e;
use Data::Dumper;
print Dumper(\%_);
print "$_\n" while $_=$_{$_};
__END__
to figure out by yourself what happens. ;-)
regards,
fabian
------------------------------
Date: 13 Apr 2005 14:29:38 -0700
From: biomahui@gmail.com
Subject: Re: can anyone explain the last two lines to me?thanks!
Message-Id: <1113427778.117153.249140@o13g2000cwo.googlegroups.com>
Thank you very much, Fabian.
Your explaination and script gives me excellent idea how it works.
Thanks again!
hui
------------------------------
Date: Wed, 13 Apr 2005 20:38:02 +0000 (UTC)
From: mjd@plover.com (Mark Jason Dominus)
Subject: Re: Comparing Regular Expressions
Message-Id: <d3jvva$l3f$1@plover.com>
In article <d30g15$729$1@sun3.bham.ac.uk>,
Brian McCauley <nobull@mail.com> wrote:
>My instinct says that will be "hard". Not just "hard" in the common
>sense, but hard in the CompSci sense of being equivalent to the halting
>problem (i.e. insoluble in the general case in finite time).
My recollection is that this is not the case. Certainly equivalence
of recursive languages is undecidable, but regular languages are
highly restricted special cases.
I may be remembering wrong, but I think regex equivalence is
NP-complete. If so, this would mean that there would be an
exponential-time algorithm for solving it. A quick google search
finds various mentions of various versions of the problem being in
PSPACE or being EXP-complete, which means that it is not undecidable.
So the problem is hard, but not impossible.
------------------------------
Date: Wed, 13 Apr 2005 21:49:51 +0200
From: Hendrik Maryns <hendrik_maryns@despammed.com>
Subject: help understanding ++
Message-Id: <1113421806.326627@seven.kulnet.kuleuven.ac.be>
Hi,
in perlop I read
----------
The auto-increment operator has a little extra builtin magic to it. If
you increment a variable that is numeric, or that has ever been used in
a numeric context, you get a normal increment. If, however, the variable
has been used in only string contexts since it was set, and has a value
that is not the empty string and matches the pattern
/^[a-zA-Z]*[0-9]*\z/, the increment is done as a string, preserving each
character within its range, with carry:
print ++($foo = '99'); # prints '100'
print ++($foo = 'a0'); # prints 'a1'
print ++($foo = 'Az'); # prints 'Ba'
print ++($foo = 'zz'); # prints 'aaa'
-----------
Can somebody please explain to me why print ++($foo = 'a0'); #
prints 'a1' rather than 'b1', and why print ++($foo = 'Az'); #
prints 'Ba' rather than 'Baa', as I would expect from the fourth example.
Or, more general: provide me with some clearer rules...
Thanks, H.
--
Hendrik Maryns
Interesting websites:
www.lieverleven.be (I cooperate)
www.eu04.com European Referendum Campaign
aouw.org The Art Of Urban Warfare
------------------------------
Date: Wed, 13 Apr 2005 20:09:44 GMT
From: Darren Dunham <ddunham@redwood.taos.com>
Subject: Re: help understanding ++
Message-Id: <c0f7e.2587$dT4.210@newssvr13.news.prodigy.com>
Hendrik Maryns <hendrik_maryns@despammed.com> wrote:
> Can somebody please explain to me why print ++($foo = 'a0'); #
> prints 'a1' rather than 'b1',
The same reason that '10' incremented becomes '11' rather than '21'.
When you increment, you increment the last character unless it is at the
end of the range (either z or 9). In this case 0 can be incremented and
will become 1.
> and why print ++($foo = 'Az'); #
> prints 'Ba' rather than 'Baa', as I would expect from the fourth
> example.
19++ => 20, not 19 => 200. You don't add a digit until all the
characters are at the end of their range.
( 99++ => 100, zz++ => aaa)
--
Darren Dunham ddunham@taos.com
Senior Technical Consultant TAOS http://www.taos.com/
Got some Dr Pepper? San Francisco, CA bay area
< This line left intentionally blank to confuse you. >
------------------------------
Date: Wed, 13 Apr 2005 22:49:43 +0200
From: Hendrik Maryns <hendrik_maryns@despammed.com>
Subject: Re: help understanding ++
Message-Id: <1113425397.999290@seven.kulnet.kuleuven.ac.be>
Darren Dunham schreef:
> Hendrik Maryns <hendrik_maryns@despammed.com> wrote:
>
>>Can somebody please explain to me why print ++($foo = 'a0'); #
>>prints 'a1' rather than 'b1',
>
>
> The same reason that '10' incremented becomes '11' rather than '21'.
>
> When you increment, you increment the last character unless it is at the
> end of the range (either z or 9). In this case 0 can be incremented and
> will become 1.
>
>
>>and why print ++($foo = 'Az'); #
>>prints 'Ba' rather than 'Baa', as I would expect from the fourth
>>example.
>
>
> 19++ => 20, not 19 => 200. You don't add a digit until all the
> characters are at the end of their range.
> ( 99++ => 100, zz++ => aaa)
Sounds logical!
Thanks.
--
Hendrik Maryns
Interesting websites:
www.lieverleven.be (I cooperate)
www.eu04.com European Referendum Campaign
aouw.org The Art Of Urban Warfare
------------------------------
Date: Wed, 13 Apr 2005 15:18:27 -0400
From: "L. D. James" <ljames@apollo3.com>
Subject: How to reverse the time localtime/gmtime function's process?
Message-Id: <115qs4562o95ob9@corp.supernews.com>
Hi Gang. I have two times in the format of:
20050413185947
20050413175146
It is broken down as, year, month, day, hour, minute and second.
2005-0413-1751-46
I would like to subtract the smaller number from the larger number. I
guess if I had an easy way to set both numbers in to seconds, that then
subtract, then convert them back to year, month, day, etc. such would work.
I'm familiar with the localtime(time) function. Is there a way to
enter the split time into a function that will give you the big number of
the time function? If I could get both numbers into a single number, then
subtract the numbers, this would be ideal.
Thanks in advance for any comments on this matter.
-- L. James
--
--------------------------------
L. D. James
ljames@apollo3.com
www.apollo3.com/~ljames
------------------------------
Date: Wed, 13 Apr 2005 22:53:37 +0200
From: Fabian Pilkowski <pilkowsk@informatik.uni-marburg.de>
Subject: Re: How to reverse the time localtime/gmtime function's process?
Message-Id: <3c5f3gF6nhmkaU1@individual.net>
* L. D. James schrieb:
> Hi Gang. I have two times in the format of:
>
> 20050413185947
> 20050413175146
>
> It is broken down as, year, month, day, hour, minute and second.
>
> 2005-0413-1751-46
>
> I would like to subtract the smaller number from the larger number. I
> guess if I had an easy way to set both numbers in to seconds, that then
> subtract, then convert them back to year, month, day, etc. such would work.
>
> I'm familiar with the localtime(time) function. Is there a way to
> enter the split time into a function that will give you the big number of
> the time function? If I could get both numbers into a single number, then
> subtract the numbers, this would be ideal.
Have a look at Time::Local. The method timelocal() should be the reverse
of localtime(), and -- not surprising that -- timegm() is reversing what
gmtime() does.
#!/usr/bin/perl
use strict;
use warnings;
use Time::Local;
sub get_time {
my @date = reverse unpack 'A4(A2)*', shift;
$date[4]--; # adjust month
timelocal( @date );
}
my $time = get_time( '20050413185947' );
print $time, "\n", scalar localtime $time;
__END__
1113411587
Wed Apr 13 18:59:47 2005
Perhaps someone would check if $date is formatted correctly to do a
reasonable error handling.
regards,
fabian
------------------------------
Date: Wed, 13 Apr 2005 20:54:35 GMT
From: "A. Sinan Unur" <1usa@llenroc.ude.invalid>
Subject: Re: How to reverse the time localtime/gmtime function's process?
Message-Id: <Xns9637ABF111486asu1cornelledu@127.0.0.1>
"L. D. James" <ljames@apollo3.com> wrote in
news:115qs4562o95ob9@corp.supernews.com:
> Hi Gang. I have two times in the format of:
>
> 20050413185947
> 20050413175146
...
> I'm familiar with the localtime(time) function. Is there a way
> to
> enter the split time into a function that will give you the big number
> of the time function? If I could get both numbers into a single
> number, then subtract the numbers, this would be ideal.
How about searching CPAN:
http://search.cpan.org/~drolsky/Time-Local-1.11/
> -- L.
> James
Your signature is not formatted properly.
Sinan
--
A. Sinan Unur <1usa@llenroc.ude.invalid>
(reverse each component and remove .invalid for email address)
comp.lang.perl.misc guidelines on the WWW:
http://mail.augustmail.com/~tadmc/clpmisc/clpmisc_guidelines.html
------------------------------
Date: Wed, 13 Apr 2005 13:56:58 -0700
From: "Mothra" <mothra@nowhereatall.com>
Subject: Re: How to reverse the time localtime/gmtime function's process?
Message-Id: <425d8687$1@usenet.ugs.com>
"L. D. James" <ljames@apollo3.com> wrote in message
news:115qs4562o95ob9@corp.supernews.com...
> Hi Gang. I have two times in the format of:
> I would like to subtract the smaller number from the larger number.
I
> guess if I had an easy way to set both numbers in to seconds, that then
> subtract, then convert them back to year, month, day, etc. such would
work.
Something like this should get you started
use strict;
use warnings;
use DateTime;
use DateTime::Format::Strptime;
my $Strp = new DateTime::Format::Strptime(
pattern => '%Y%m%d%H%M%S',
time_zone => 'floating',
);
my @data;
while (<DATA>) {
push(@data, $Strp->parse_datetime($_) );
}
print map { $_->epoch(), "\n" } @data;
__DATA__
20050413185947
20050413175146
------------------------------
Date: 13 Apr 2005 11:12:26 -0700
From: anywherenotes@gmail.com
Subject: how to run perl script from a perl script?
Message-Id: <1113415946.170999.72870@l41g2000cwc.googlegroups.com>
I have a rather interesting requirement.
I have 2 perl scripts, and one of them should execute the other one.
So lets say script a.pl should execute script b.pl.
The output of the script b.pl should go into a specific file which only
a.pl knows about.
So I could do this from a.pl:
system("perl b.pl >>mylog.log 2>&1");
But is there a better way?
Currently I am doing this:
require "b.pl";
But it doesn't redirect the output as I want it to.
I am a perl noobie, so I am probably overlooking the correct way of
doing this.
------------------------------
Date: 13 Apr 2005 18:32:14 GMT
From: xhoster@gmail.com
Subject: Re: how to run perl script from a perl script?
Message-Id: <20050413143214.963$bx@newsreader.com>
anywherenotes@gmail.com wrote:
> I have a rather interesting requirement.
>
> I have 2 perl scripts, and one of them should execute the other one.
> So lets say script a.pl should execute script b.pl.
>
> The output of the script b.pl should go into a specific file which only
> a.pl knows about.
I think "interesting" is the very polite way of describing your
requirement. It would probably make more sense to refine your requirement,
rather than refine your method of achieving the that requirement.
>
> So I could do this from a.pl:
> system("perl b.pl >>mylog.log 2>&1");
>
> But is there a better way?
What do you mean by better? Faster? Less memory? Easier to maintain?
Fewer keystrokes? More secure? More intuitive? More portable?
> Currently I am doing this:
> require "b.pl";
>
> But it doesn't redirect the output as I want it to.
redirect STDOUT (and it looks like STDERR) before the 'require "b.pl";'
Better yet, turn b.pl into a module (and preferably rename it) which
defines a subroutine that takes a file handle as an argument and prints its
output to that filehandle.
Then just do:
use b;
open my $fh, ">whatever" or die $!;
b::run($fh);
> I am a perl noobie, so I am probably overlooking the correct way of
> doing this.
Xho
--
-------------------- http://NewsReader.Com/ --------------------
Usenet Newsgroup Service $9.95/Month 30GB
------------------------------
Date: Wed, 13 Apr 2005 22:29:20 +0200
From: peter pilsl <pilsl@goldfisch.at>
Subject: Re: how to run perl script from a perl script?
Message-Id: <425d8123$0$1948$79720d31@newsreader.inode.at>
anywherenotes@gmail.com wrote:
>
> I have 2 perl scripts, and one of them should execute the other one.
> So lets say script a.pl should execute script b.pl.
>
> The output of the script b.pl should go into a specific file which only
> a.pl knows about.
>
Why not include the code from b.pl in a.pl. Directly or via a module?
If this is not possible or you need only a quick fix, then take a look
at pipes. You can pipe the output from b.pl directly into a.pl without
needing a temporary file, that - according to your requirements - is a
potential securityrisk when read by someone else.
And of course you can redirect STDOUT as Xho stated, but I'm not sure if
this is the best approach to your problem.
best,
peter
--
http://www.goldfisch.at/know_list
------------------------------
Date: 13 Apr 2005 14:08:38 -0700
From: anywherenotes@gmail.com
Subject: Re: how to run perl script from a perl script?
Message-Id: <1113426518.584156.270090@l41g2000cwc.googlegroups.com>
Thank you for both replies. I don't want to put code from b.pl to
a.pl (not actual names, they do have normal names) because it's likely
someone would want to run "b.pl" independently of a.pl.
Basically a.pl checks for lots of things wrong with the system. b.pl
checks for only a couple of things, so a.pl calls b.pl to do some
checking.
I am currently using pipes, as I found that I couldn't use system the
way I described. Something that I don't know how to do on Windows I
guess ... or I'll just call it a windows bug :) - it works fine on Unix
(see below in case you can solve it).
$ cat a.pl
open LOG, ">>mylog.log" or die "can't open log\n";
system ("perl b.pl >>mylog.log");
close LOG;
$ cat b.pl
print "b.pl";
$ perl a.pl
The process cannot access the file because it is being used by another
process.
$
------------------------------
Date: Wed, 13 Apr 2005 14:39:50 -0500
From: brian d foy <comdog@panix.com>
Subject: Re: Is Perl open source?
Message-Id: <130420051439508227%comdog@panix.com>
In article <1113355491.285810.321470@f14g2000cwb.googlegroups.com>,
<soup_or_power@yahoo.com> wrote:
> If much of perl is implemented in C, why should we prefer Perl over C
> for performance critical projects?
You really can't answer this question without knowing about the
particular project. No tool is going to be the best thing to use in
every situation.
Perl does have many ways to let you drop down to C if you decide that
you really need to do that.
--
brian d foy, comdog@panix.com
Subscribe to The Perl Review: http://www.theperlreview.com
------------------------------
Date: Wed, 13 Apr 2005 15:12:12 -0400
From: Ted Zlatanov <tzz@lifelogs.com>
Subject: is there a minimal LDAP server written in Perl?
Message-Id: <4n7jj65w4z.fsf@lifelogs.com>
I did searches on this, but there don't appear to be any LDAP servers
written in Perl. Net::LDAP has modules that will help with the task,
sure, but no one has put them together.
I am interested in writing such a beast for minimal read-only access
to a list of entries (with more functionality later, perhaps), so
before I begin I want to make sure I'm not reinventing the wheel.
Does anyone know?
Thanks
Ted
----== Posted via Newsfeeds.Com - Unlimited-Uncensored-Secure Usenet News==----
http://www.newsfeeds.com The #1 Newsgroup Service in the World! 120,000+ Newsgroups
----= East and West-Coast Server Farms - Total Privacy via Encryption =----
------------------------------
Date: Wed, 13 Apr 2005 22:35:12 +0100
From: Brian Wakem <no@email.com>
Subject: Re: LWP::UserAgent and basic authentication
Message-Id: <3c5hkgF6k0gvcU1@individual.net>
Thomas Kratz wrote:
> Brian Wakem wrote:
>
>> I have not read the docs but I do it like this -
>>
>> my $ua = LWP::UserAgent->new;
>> $ua->agent("MyAgent/1.0");
>> my $req = HTTP::Request->new(GET => $url);
>> $req->authorization_basic('user', 'pass');
>> my $res = $ua->request($req);
>
> authorization_basic does not work for me, because I have to set a special
> realm with $ua->credentials.
>
>>
>> And I can say without any doubt (observing the access_log of the server
>> it speaks to) that it passes the user/pass *straight away*.
>
> Perhaps I misread the code of the request method. But the first thing it
> does is call $ua->simple_request, and I cannot see any call to
> LWP::Authen::Basic there.
>
> Could you please add a:
> use LWP::Debug qw(+);
> at the top of your code
Have done. I get -
LWP::UserAgent::new: ()
LWP::UserAgent::request: ()
LWP::UserAgent::send_request: GET <url>
LWP::UserAgent::_need_proxy: Not proxied
LWP::Protocol::http::request: ()
LWP::Protocol::collect: read 841 bytes
LWP::Protocol::collect: read 976 bytes
LWP::Protocol::collect: read 1017 bytes
LWP::Protocol::collect: read 426 bytes
LWP::Protocol::collect: read 1448 bytes
LWP::Protocol::collect: read 171 bytes
LWP::Protocol::collect: read 1017 bytes
LWP::Protocol::collect: read 47 bytes
LWP::Protocol::collect: read 7 bytes
LWP::Protocol::collect: read 186 bytes
LWP::Protocol::collect: read 1448 bytes
LWP::Protocol::collect: read 1448 bytes
LWP::Protocol::collect: read 1448 bytes
LWP::Protocol::collect: read 1448 bytes
LWP::Protocol::collect: read 1448 bytes
LWP::Protocol::collect: read 1448 bytes
LWP::Protocol::collect: read 378 bytes
LWP::Protocol::collect: read 1016 bytes
LWP::Protocol::collect: read 46 bytes
LWP::Protocol::collect: read 1448 bytes
LWP::Protocol::collect: read 1448 bytes
LWP::Protocol::collect: read 1448 bytes
LWP::Protocol::collect: read 2786 bytes
LWP::Protocol::collect: read 1016 bytes
LWP::Protocol::collect: read 534 bytes
LWP::Protocol::collect: read 1448 bytes
LWP::Protocol::collect: read 1448 bytes
LWP::Protocol::collect: read 1448 bytes
LWP::Protocol::collect: read 1448 bytes
LWP::Protocol::collect: read 850 bytes
LWP::Protocol::collect: read 591 bytes
LWP::Protocol::collect: read 1448 bytes
LWP::Protocol::collect: read 1072 bytes
LWP::Protocol::collect: read 369 bytes
LWP::Protocol::collect: read 200 bytes
LWP::Protocol::collect: read 15 bytes
LWP::UserAgent::request: Simple response: OK
--
Brian Wakem
------------------------------
Date: Wed, 13 Apr 2005 20:37:48 +0300
From: Ilmari Karonen <usenet@vyznev.invalid>
Subject: Re: Matching mixed up words
Message-Id: <slrnd5qm7c.89u.usenet@boojum.home.vyznev.net>
Anno Siegel <anno4000@lublin.zrz.tu-berlin.de> kirjoitti 13.04.2005:
> A. Sinan Unur <1usa@llenroc.ude.invalid> wrote in comp.lang.perl.misc:
>> DAVISM@ecr6.ohio-state.edu (Michael T. Davis) wrote in
>> news:d3h7bu$hbt$1@charm.magnus.acs.ohio-state.edu:
>
> [how to test for anagrams]
>
>> I am sure someone will show a regex solution that I have overlooked.
>
> A regex solution seems unlikely. It would require jumping back and
> forth in a string while keeping track of what was matched where.
> Regexes aren't very good at that.
Nonetheless, here's a regex solution:
sub anagram_re {
my $word = shift;
return "" if $word eq "";
my (@re, %seen);
foreach my $i (0 .. length($word)-1) {
my $temp = $word;
my $ch = substr($temp, $i, 1, "");
next if $seen{$ch}++;
push @re, quotemeta($ch) . anagram_re($temp);
}
return @re > 1 ? "(?:".join("|", @re).")" : $re[0];
}
Give it a word, and it will return a regex to match any anagram of it.
For example, here's the regex for "food" (sans "?:" modifiers):
(f(o(od|do)|doo)|o(f(od|do)|o(fd|df)|d(fo|of))|d(foo|o(fo|of)))
The corresponding regex for "gremlin" is 33218 characters long with
the "?:" modifiers, or 25978 without them.
--
Ilmari Karonen
To reply by e-mail, please replace ".invalid" with ".net" in address.
------------------------------
Date: Wed, 13 Apr 2005 23:12:56 +0200
From: "HC" <assegai@planet.nl>
Subject: Net::Telnet in a foreach loop
Message-Id: <d3k20o$dif$1@reader13.wxs.nl>
Hi all,
I wrote a script and I can nog get the errmode to work right but before I
start asking questions on the errmode problem I wanted to ask another
question first.
When doing a script using Net::Telnet to telnet to several hosts where would
the $obj = Net::Telnet->new( ) be placed in the foreach loop?
$obj = Net::Telnet->new( );
foreach $host (@hosts) {
$obj->open($host);
#do your login and cmd's here
}
OR
foreach $host (@hosts){
$obj = Net::Telnet->new( );
$obj->open($host);
#do loging and cmd's here
}
I asume that using the wrong method might be a reason for the errmode not to
work right. I am using the first method described right now...
Thanks for the help.
HC
------------------------------
Date: 13 Apr 2005 12:22:39 -0700
From: colintelfer@hotmail.com
Subject: Net::Telnet prompt problem
Message-Id: <1113420159.266121.303160@l41g2000cwc.googlegroups.com>
I get this error when running my small test program...
timed-out waiting for login prompt
...
$host = '192.168.100.251';
$port = '24';
$username = 'admin';
$password = '';
$prompt = '/User:/';
$session = new Net::Telnet
(
Timeout => 5,
Prompt => $prompt
);
$session->input_log("inputlog.txt");
$session -> open(Host => $host,Port => $port);
$session -> login($username, $password);
...
Here is the ouput from inputlog.txt:
(Sys)
User:
I am guessing there is a problem with prompt, but I have tried a few
different matches without success...
Any help?
Thanks!
------------------------------
Date: Wed, 13 Apr 2005 22:04:53 +0200
From: Hendrik Maryns <hendrik_maryns@despammed.com>
Subject: suggestion for perlop
Message-Id: <1113422708.683157@seven.kulnet.kuleuven.ac.be>
Hi,
I'm reading through perlop, and encountered the following:
---------
Unary ``+'' has no effect whatsoever, even on strings. It is useful
syntactically for separating a function name from a parenthesized
expression that would otherwise be interpreted as the complete list of
function arguments. (See examples above under Terms and List Operators
(Leftward).)
---------
But in Terms and List Operators, + is not used (as far as I can tell).
Instead, it is used in the section Named Unary Operators. I suppose
this should be changed.
If this isn't the right place for such a suggestion, please point me to
a better one.
Cheers, H.
--
Hendrik Maryns
Interesting websites:
www.lieverleven.be (I cooperate)
www.eu04.com European Referendum Campaign
aouw.org The Art Of Urban Warfare
------------------------------
Date: Wed, 13 Apr 2005 22:14:28 +0300
From: Nikos <hackeras@gmail.com>
Subject: Re: Web Interface and index.pl separated?!?
Message-Id: <d3jr2h$d3o$1@nic.grnet.gr>
Tad McClellan wrote:
> Nikos <hackeras@gmail.com> wrote:
> That is a mighty strange name for a webpage.
>
> They usually have a .html or .htm filename extension...
> You cannot put Perl code into a webpage.
>
> (well you can, but it will not be executed, so what would be the point?)
Itc a CGI script. My webpage is locates at http://www.nikolas.tk and the
index file is not a index.html but an index.pl
Problem is that i have both the web interface and the stuff iam doing
with it in asingle file(index.pl).
I just want to know if its better to separate Perl code and maybe design
the interface with Dreamweaver for example.
The question is if the the 2 things will be able to cooperate in somw way.
------------------------------
Date: Wed, 13 Apr 2005 14:53:52 -0500
From: "J. Gleixner" <glex_nospam@qwest.invalid>
Subject: Re: Web Interface and index.pl separated?!?
Message-Id: <lNe7e.50$Or4.531@news.uswest.net>
Nikos wrote:
>
> I just want to know if its better to separate Perl code and maybe design
> the interface with Dreamweaver for example.
>
> The question is if the the 2 things will be able to cooperate in somw way.
For one page, it doesn't matter, do it however you'd like and move on.
For multiple pages, Web based applications, etc. then yes, separate your
HTML from your code, and separate your Javascript and CSS while you're
at it.
There are many perl based systems already developed. HTML::Template,
Template Toolkit, HTML::Mason, etc. There is a lot of documentation
along with many tutorials available.
However. Looking at your original example, it doesn't appear that you
have any need to do anything dynamic. If you don't need to change/add
anything on your page, like set variables/layout based on user input,
time of day, database query, etc. then don't make it a script/CGI, just
use HTML. Use whatever you want to design the HTML.
------------------------------
Date: Thu, 14 Apr 2005 00:37:39 +0300
From: Nikos <hackeras@gmail.com>
Subject: Re: Web Interface and index.pl separated?!?
Message-Id: <d3k3ev$l8p$1@nic.grnet.gr>
J. Gleixner wrote:
> However. Looking at your original example, it doesn't appear that you
> have any need to do anything dynamic. If you don't need to change/add
> anything on your page, like set variables/layout based on user input,
> time of day, database query, etc. then don't make it a script/CGI, just
> use HTML. Use whatever you want to design the HTML.
My webpage is dynamic, read time and makes mysql database query.
I use cgi.pm because i dont want to have p[ure html in my page.
But i think it might be better if i create the graphicss with
dreamweaver. but then would that graph.html work with with indx.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 7972
***************************************