Help - Search - Member List - Calendar
Full Version: combinations
WorkTheWeb Forums > Webmaster Resources > Perl Beginner Help
Pages: 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44
Support our Sponsors!
Dan Muey
QUOTE
http://www.perl.com/pub/a/2004/01/09/survey.html
Nice!


Drieux
On Jan 17, 2004, at 2:35 PM, Dan Muey wrote:
[..]
QUOTE
http://www.perl.com/pub/a/2004/01/09/survey.html
Nice!

folks may also take a look under the covers
in the blogWare that is popular amongst various
blogs out there. they might also look at what
is under the covers in the wikipedia movement.

So the fact that perl is in use, and not self
identifying itself as perl, as opposed to *.php
or *.jsp or *.asp, might be an 'issue' for some.

But the real question remains, are you using the
right coding language for the problem in front of you,
or are you trying to work around your coding language.


ciao
drieux

---

James Edward Gray II
On Jan 17, 2004, at 3:51 PM, James Edward Gray II wrote:

QUOTE
A recent article on Perl.com covered this a little:

http://www.perl.com/pub/a/2004/01/09/survey.html

And look what I read on Slashdot today:

http://developers.slashdot.org/article.pl?sid=04/01/17/
1435206&mode=thread&tid=100&tid=126&tid=137&tid=145&tid=156

Heck, isn't the Slash code Perl too?

Perl's out there somewhere.

James

Luke Bakken
QUOTE
Most of the scripts I see end in an extension like .jsp,
.asp, .dll, or
something which says that they aren't perl.  Is there a reason more
businesses and online companies don't use perl?

-Dan

I would bet just about every major company uses Perl in one way or
another. The financial company for whose loan software I write uses Perl
all over the place. Just because you don't see it via their web presence
doesn't mean it's not there.

Tassilo Von Parseval
On Sat, Jan 17, 2004 at 06:52:27PM -0600 James Edward Gray II wrote:
QUOTE
On Jan 17, 2004, at 3:51 PM, James Edward Gray II wrote:

A recent article on Perl.com covered this a little:

http://www.perl.com/pub/a/2004/01/09/survey.html

And look what I read on Slashdot today:

http://developers.slashdot.org/article.pl?sid=04/01/17/
1435206&mode=thread&tid=100&tid=126&tid=137&tid=145&tid=156

See also

<http://www.theregister.co.uk/content/64/34943.html>

on the same issue.

QUOTE
Heck, isn't the Slash code Perl too?

Yes.

Tassilo
--
$_=q#",}])!JAPH!qq(tsuJ[{@"tnirp}3..0}_$;//::niam/s~=)]3[))_$-3(rellac(=_$({
pam{rekcahbus})(rekcah{lrePbus})(lreP{rehtonabus})!JAPH!qq(rehtona{tsuJbus#;
$_=reverse,s+(?<=sub).+q#q!'"qq.t$&."'!#+sexisexiixesixeseg;y~n~~dddd;eval

Wiggins D'Anconia
Bakken, Luke wrote:

QUOTE
Most of the scripts I see end in an extension like .jsp,
.asp, .dll, or
something which says that they aren't perl.  Is there a reason more
businesses and online companies don't use perl?

-Dan


I would bet just about every major company uses Perl in one way or
another. The financial company for whose loan software I write uses Perl
all over the place. Just because you don't see it via their web presence
doesn't mean it's not there.


From what I have seen and heard this is certainly true. My current
employer (Fortune 500) employs me to hack on an application almost
exclusively in Perl which has no web presence (the app, not the
company). Though the web stuffs at the company are handled in ASP, and
in general are hugely cost ineffective and overdesigned. I think this
is somewhat regional in nature, OSS has a much bigger presence on the
two coasts (of the US) and much less presence in the heartland, this can
also be said about Unix/Linux.

What I would like to see is more embracing of Perl to handle non-web
enabled apps (though most apps these days are getting web enabled), or
at least where the web portion is not the primary function of the app. C
and C++ apps are a huge target where absolute speed is not needed, I
won't even mention the nightmare that are legacy systems JCL this and
COBOL that... Based on postings on jobs.perl.org, Yahoo and Amazon are
two of the big internet guys using Perl, Google does as well, and I know
AOL has a significant POE application running behind the scenes.

Though it is always an interesting question of why must Perl become
bigger? "Is it for His glory, or yours?" (name that movie)....

http://danconia.org

Gabor Urban
Hi,

I might know something for an answer. Though Perl is really good and
fantastic, flexibole, etc. it has the bad reputation being hard to
read. An average manager wants his or her stuff to be clean and
neat. Seeing a tricky Perl code with regexp stuff is rather alarming.

On the other hand Python seems to boom these days (but not MUCH better
readability..) as was Java before.

G

Drieux
On Jan 18, 2004, at 11:58 PM, Gabor Urban wrote:

QUOTE
I might know something for an answer. Though Perl is really good and
fantastic, flexibole, etc. it has the bad reputation being hard to
read. An average manager wants his or her stuff to be clean and
neat. Seeing a tricky Perl code with regexp stuff is rather alarming.

On the other hand Python seems to boom these days (but not MUCH better
readability..) as was Java before.

My compliments to your wit!

As most folks know, there are the obligatory
"obfuscatory <yourProgrammingLanguageHere> contests"
that are designed to establish the specific 'unreadablity'
standards for a given language. Perl, like all proper
modern languages, has such a contest.

I remember back in 1991 when the Pythonites were trying
to sell the idea that it was better than Perl4 because
unlike Perl4, it was natively OO-ish, hence cooler by
the HipBuzzDuJure...

A part of the problem with these 'language comparison'
types of problem remains how to differenciate the merely
comical from the simply amusing aspects about why the
advocates advocate using Foo over Bar. If one stumbles
into the 'read ability' giggler, then one should deal
with the 'real issue' of "so why did you accept the
code without the Proper POD and internal comments?"


ciao
drieux

---

Wiggins D'Anconia
Lost my other thread sorry this is listed as a new topic.

Going through some of my older e-mails finally from vacation, and there
was an article from 01/15/2004 that pertains to the conversation or could...

http://use.perl.org/article.pl?sid=04/01/15/1942236&tid= (news posting)
http://www.perl.com/pub/a/2004/01/09/survey.html (actual article)

http://danconia.org

James Edward Gray II
On Jan 19, 2004, at 4:33 PM, wolf blaum wrote:

QUOTE
Hi there,

Hello.

QUOTE
I do have one type A file, that holds about 25.000 A-ids, one per line.
Furher I have 500 type B files in a dir that hold 10-500 B-ids each,
one per
line.
All files are -T
Now i want to generate 500 type C files, corrosponding to the b files:

each B-id, that occours in a B-type file AND the A-type file should go
into
the corrosponding C-file.

That sounds simple enough.

QUOTE
Each A id is unique in the A file, each B-id is unique in its file BUT
NOT i
all the Bfiles: each B id may occure in one or more B files.

Im lookin for a fast and memory concious way to do that.

Hmm, both are relative and probably don't go together well here. Is
reading 25,001 ids into memory, conscious enough? That would be my
first choice.

(Note: The following code works with lines, not ids, since I don't
know what they are like. It's also untested code.)

#!/usr/bin/perl

use strict;
use warnings;

open A_FILE, '<', 'a_id_file.txt' or die "File error: $!";
my @a_ids;
while (<A_FILE>) {
chomp;
push @a_ids, $_;
}
close A_FILE;

open C_FILE, '>', 'c_id_file.txt' or die "File error: $!";
opendir B_DIR, 'b_directory' or die "Directory error: $!";
while (defined(my $b_file = readdir B_DIR)) {
next if $b_file =~ /^./; # or whatever filtering you need
open B_FILE, '<', $b_file or die "File error: $!";
while (<B_FILE>) {
chomp;
for my $index (0..$#a_ids) {
if ($_ eq $a_ids[$index]) {
print C_FILE "$_n";
splice @a_ids, $index, 1; # remove from a's prevent duplicates
last;
}
}
}
close B_FILE;
}
close C_FILE;

__END__

That's probably not perfect, but hopefully it gets you moving in the
right direction.

If you don't want to stuff the Type-A IDs in memory like that, you may
have to go line by line with the B files, reading all of A to check for
a match, as you originally showed. But don't do that, if you can avoid
it. That could be pretty slow.

James

Nagendra
All,

Can anybody tell me , how to pack binary array into string of 32 bit words adn
print into hexa,

$word2 = pack ("C", @line1[32 .. 63]);


But nothing happens here. Also I want to do it character by character packing


$word1 = pack("C", $line1[316], $line1[318], $line1[320], $line1[322],
$line1[324], $line1[326],$line1[328],$line1[330],$line1[332], $l
ine1[334],$line1[336],$line1[338],$line1[340],$line1[342],$line1[344],$line1[346
],$line1[348],$line1[350],
$line1[352],$line1[354],$line1
[356],$line1[338],$line1[338],$line1[338],$line1[338],$line1[338],$line1[338],$l
ine1[338]);



Something like above. I intend to get back 32 strings, which I can print in
Hexa.


Thanks
Nagendra

Bastian Angerstein
Thanks a lot people!

Have a nice day,
Bastian

Sander
"James Edward Gray II" <[Email Removed]> wrote in message
news:[Email Removed]...
QUOTE
On Jan 19, 2004, at 3:23 PM, Sander wrote:

I have a simple form that I have been using for a while, but now I
need to
send the data to two email addresses. What is the simplest way to
achieve
this?

I have tried various combinations and can't seem to figure it out.
$emailId
= '[Email Removed]' '[Email Removed]'; ???

This depends a lot on the program, module, etc. you are using the send
the message.  I'm not familiar with the program you list below, but
I'll at least venture a guess:

$emailId = '[Email Removed], [Email Removed]';

Give that a try.

If it doesn't work, why don't you try sending us the part of the code
that actually sends a message, instead of the snippet below.

Good luck.

James

James,

Thanks for the response but that doesn't seem to work either. Maybe it
would be easier just to create a distribution list on the email server and
just put that address in my script.



QUOTE

Here is my code right now:


#!/usr/bin/perl

use CGI param;
$p = CGI::new();

$mailProgram = '/var/qmail/bin/qmail-inject';


# Email id to send the email to
$emailId = '[Email Removed]';

print "Content-type: text/htmlnn";
# Get the form variables

___________________

Any help would be appreciated.

Thanks,

Sander






--
To unsubscribe, e-mail: [Email Removed]
For additional commands, e-mail: [Email Removed]
<http://learn.perl.org/> <http://learn.perl.org/first-response





Dan Muey
QUOTE

Thanks for the response but that doesn't seem to work either.
Maybe it would be easier just to create a distribution list
on the email server and just put that address in my script.


It doesn't work, looping over an array does not work?

for(@emaillist) {
# pipe $_ to qmail inject like you do now here
}

You might also want to try a module that doesn't rely on
an external program's argument syntax but does an SMTP session directly.
(don't get em wrong qmail rocks but you should avoid avoid external program when ever possible to make your code more portable, reliabel;, etc etc)
Try Mail::Sender it is very sexxy. You can use a commas separated list of address in one variable as your To field.

HTH

DMuey

Bradley A. Brown
I use Mail::Sender on a daily basis for several things in a production
environment and it works beautifully. Its easy to use and allows for email
attachments as well!!!
Bradley

-----Original Message-----
From: Dan Muey [mailto:[Email Removed]]
Sent: Tuesday, January 20, 2004 10:26 AM
To: Sander; [Email Removed]
Subject: RE: How to send results to more than one recipient


QUOTE

Thanks for the response but that doesn't seem to work either.
Maybe it would be easier just to create a distribution list
on the email server and just put that address in my script.


It doesn't work, looping over an array does not work?

for(@emaillist) {
# pipe $_ to qmail inject like you do now here
}

You might also want to try a module that doesn't rely on
an external program's argument syntax but does an SMTP session directly.
(don't get em wrong qmail rocks but you should avoid avoid external program
when ever possible to make your code more portable, reliabel;, etc etc)
Try Mail::Sender it is very sexxy. You can use a commas separated list of
address in one variable as your To field.

HTH

DMuey

--
To unsubscribe, e-mail: [Email Removed]
For additional commands, e-mail: [Email Removed]
<http://learn.perl.org/> <http://learn.perl.org/first-response>

James Edward Gray II
On Jan 20, 2004, at 8:47 AM, Sander wrote:

QUOTE
James,

Thanks for the response but that doesn't seem to work either.  Maybe it
would be easier just to create a distribution list on the email server
and
just put that address in my script.

That's definitely a way to go.

Other choices: Send us the part of the code that actually sends a
message, so we can work with that and hopefully provide more useful
suggestions.

Or, take a look at the qmail-inject man page to see if you can figure
out the change that needs to be made. You can find that here:

http://www.qmail.org/man/man8/qmail-inject.html

James

Wiggins D Anconia
QUOTE
Hi all, I could use some help with an expression or code to delete
multiple blank lines and replace it with only one blank line...

I know how this can be done in sed, but am not sure how to do it in
perl...

Thanks,
Taylor

Well you could do this the simple way, use a switch that toggles on/off
whether the last line you checked was empty. If the switch is on, and
the current line is empty simply skip it. If the switch is off and the
current line is empty then keep it, toggle the switch and move on.

KISS,

http://danconia.org

Paul Johnson
On Tue, Jan 20, 2004 at 12:39:55PM -0600, Lewick, Taylor wrote:

QUOTE
Hi all, I could use some help with an expression or code to delete
multiple blank lines and replace it with only one blank line...

I know how this can be done in sed, but am not sure how to do it in
perl...

perl -i~ -p00e0 file1 file2 ...

perldoc perlrun

--
Paul Johnson - [Email Removed]
http://www.pjcj.net

James Edward Gray II
On Jan 20, 2004, at 12:39 PM, Lewick, Taylor wrote:

QUOTE
Hi all, I could use some help with an expression or code to delete
multiple blank lines and replace it with only one blank line...

I know how this can be done in sed, but am not sure how to do it in
perl...

Well, if slurping is okay (read: file size is reasonable), I would
probably use something like this (untested code):

#!/usr/bin/perl

use strict;
use warnings;

die "Usage: perl script_name OLD_FILE NEW_FILEn" unless @ARGV == 2;

open OLD, '<', shift() or die "File error: $!n";
my $text = join '', <OLD>;
close OLD;

$text =~ s/n(?:s*n)+/n/g;

open NEW, '<', shift() or die "File error: $!n";
print NEW $text;
close NEW;

__END__

Hope that helps.

James

David
Nagendra wrote:

QUOTE
All,

Can anybody tell me , how to pack binary array into string of 32 bit words
adn print into hexa,

$word2 = pack ("C", @line1[32 .. 63]);


try:

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

my $c = pack('C*',map ord,split(//,'a line of text'));

print join('',unpack('a*',$c)),"n";

__END__

prints:

a line of text

i am not sure if that's what you want.

david
--
sub'_{print"@_ ";* = * __ , & }
sub'__{print"@_ ";* = * ___ , & }
sub'___{print"@_ ";* = * ____ , & }
sub'____{print"@_,n"}&{_+Just}(another)->(Perl)->(Hacker)

James Edward Gray II
On Jan 20, 2004, at 1:01 PM, Paul Johnson wrote:

QUOTE
perl -i~ -p00e0 file1 file2 ...

Wow! I've been over here trying to explain to myself why that works.
Help me out a little.

Broken down those switches are:

-i~ -p -00e0

Right?

No problems with the first two here. The third sets the input record
separator to 0e0, I think. My 'perlrun' said 00 was a special value
used to get "paragraph mode". I'm going to assume 0e0 does the same
thing.

Here's where I'm fuzzy though, does "paragraph mode" only leave one n
at the end of $_? I didn't know that. Is it true even if you set if
the usual way?

local $/ = '';

One last question, does "paragraph mode" consider lines with only
spaces "blank lines" or must it be back-to-back newlines?

Thanks for the lesson!

James

Wiggins D'Anconia
Lewick, Taylor wrote:
QUOTE
Thanks to everyone's help so far, I think I am getting better with
Regular expressions...


Don't know if they have been mentioned, if not:

perldoc perlretut
perldoc perlre

QUOTE


Need a little help on this one

This is sample data, not accurate..



1. St Joes (15-0)

.875

(2-0)

2. Kentucky (12-2)

.850

(1-0)

10. Kansas (12-2)

.778

(1-1)

198 Crappy School (2-9)


Note: there is not (.) after 198... is your data sane?

QUOTE
.233



I think I went to Crappy School, good parties... ;-)

QUOTE

and on and on..

I am trying to match only the schools name, and I have the following reg
ex



if (/^d.s([A-Z]D+)/)  (This says match starting at the beginning of
the line a digit followed by a period followed by a space followed by a
Capital letter followed by any amount of nondigit characters)



This matches the schools that are 1 through 9, but not 10-200.



What is the best way to say match  1, 2 or 3 numbers?  With a plus after
the d or do can I tell it to specifically match only 1 2 or 3 digits?


There are lots of possiblities. Naturally the dd?d? works, which is
just a digit followed by 2 optional digits, d+ will get any number of
digits in a row but won't be limited to 3. There are also combinations
with braces, such as, d{1,3} which is match at least once but not more
than 3 times (see perlre above).

QUOTE


Also, this is returning the first parentheses mark "(".  How do I tell
it not to match that... I know I have to replace D+ but what with?
What is the metacharacter if there is one to just match a letter?


A word character which includes your digits would be w, you can also
use character classes such as [A-Za-z]. You might want to consider using
a word boundary b. As above there are lots of ways to do it. Note that
one of the names of the schools has a space so this will not be
sufficient. One possible way:

if ($string =~ /^d{1,3}.s([ws]+)s(d+-d+)/) {
print "Matched: $1n";
}

Can't stress enough how important reading the docs is.....

HTH,

http://danconia.org

James Edward Gray II
On Jan 20, 2004, at 4:28 PM, Lewick, Taylor wrote:

QUOTE
Thanks to everyone's help so far, I think I am getting better with
Regular expressions...



Need a little help on this one

This is sample data, not accurate..



1. St Joes (15-0)

.875

(2-0)

2. Kentucky (12-2)

.850

(1-0)

10. Kansas (12-2)

.778

(1-1)

198 Crappy School (2-9)

.233



and on and on..

I am trying to match only the schools name, and I have the following
reg
ex



if (/^d.s([A-Z]D+)/)  (This says match starting at the beginning of
the line a digit followed by a period followed by a space followed by a
Capital letter followed by any amount of nondigit characters)



This matches the schools that are 1 through 9, but not 10-200.



What is the best way to say match  1, 2 or 3 numbers?  With a plus
after
the d or do can I tell it to specifically match only 1 2 or 3 digits?

You could do either:

d+ # one or more digits

d{1,3} # one to three digits

I actually prefer the first. It's simpler, should work just fine with
the period to keep us from grabbing too much, and is even more flexible
since it can handle bigger numbers.

QUOTE
Also, this is returning the first parentheses mark "(".  How do I tell
it not to match that... I know I have to replace D+ but what with?
What is the metacharacter if there is one to just match a letter?

m/
^d+.s+ # a number, followed by a period and some whitespace
([A-Za-z ]+?) # the school name, one or more letters and spaces,
capture
s+( # some whitespace and a paren
[^)]+ # one or more non-paren characters
)s*$ # final paren, optional whitespace, end of line
/x

If you need to capture other parts, just add parens. You really don't
even need the last two lines of the expression, if you only want to
capture the school name.

Good luck.

James

Dan Muey
QUOTE
I am transferring the data from a Redhat 9 machine to an IIS

There's your first mistake, moving *from* Redhat *to* IIS :)

QUOTE
server run by my ISP.  I just tried running rsync and it was

Assuming it was using ssh, does the winblows server have ssh servce on it?

QUOTE
not responsive (left it on overnight in fact to give it time

Where their any errors at all or just a blank stare?
There could be a zillion things, authentication, connection,
the fact that windows sucks, etc, etc... If there were any errors use them.


QUOTE
to try).  :(


What was the Perl question again? You might want to post to an
rsync list, they'll probably be able to help better.

QUOTE
Thanks!

Robert


Ajit P Singh
Hello Friends,

I am trying to get the prompt parameter right for my Telnet connection.
Doesnt seem to be working...

can somebody help me out with this ...

The prompt from my remote host(cisco box) is as shown below:

W9-BAS-01>

$t = new Net::Telnet (Timeout => 10,
Input_log => $inlogfileg,
Output_log => $outlogfile,
Telnetmode => 1,
dump_log => $dmplog,
Timeout => $secs),
Prompt => 'W9-BAS-01');


Error message:

syntax error at Bastelnet.pl line 18, near "'W9-BAS-01')"
Execution of Bastelnet.pl aborted due to compilation errors.


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

regards,

Ajitpal Singh,

Owen
On Fri, 23 Jan 2004 11:45:08 -0000
"Singh, Ajit p" <[Email Removed]> wrote:

QUOTE
Timeout => $secs),
Prompt => 'W9-BAS-01');

What is the ) doing on line 17?

--
Owen

Owen
On Fri, 23 Jan 2004 13:24:24 -0000
"Singh, Ajit p" <[Email Removed]> wrote:

QUOTE
Thanks Owen for your reply.

that was a typo, however i m getting the below error message now..

$t = new Net::Telnet (Timeout => 10,
Input_log => $inlogfileg,
Output_log => $outlogfile,
Telnetmode => 1,
dump_log => $dmplog,
Timeout => $secs,
Prompt => 'W9-BAS-01');
#    Prompt => '/bash$ $/');
$t->open("hostname");

Error message:
ignoring bad Prompt argument "W9-BAS-01": missing opening delimiter of match
operator at Bastelnet.pl line 12

Please don't reply to me personally, reply to the list.

Try something like this

my $t = Net::Telnet->new(Host=>"hostname",
Timeout=>$secs;
Dump_log=>$dump_log); # assign $dump_log

$t->waitfor('/W9-BAS-01/') || die "bad $1";
$t->print ("$whatever");


Read perdoc Net::Telnet

Read the dumplog, it often contains clues as to what is happening




--
Owen

John McKown
Unfortunately, if the person is writing from work, the disclaimer is
likely required by his employer. I know that I have a similar one at work.
And not including it is grounds for termination <stupid>.

The only way around this is to use a personal email, like I do. But he may
need the help for work and at work. Supposedly, I cannot use my personal
email from work. But I know ways and means around it and am stealthy
enough that I am not likely to get caught.

I'm sitting at work now, but using my home email.

--
Maranatha!
John McKown

Luinrandir Hernsen
Hallo everyone and thank you for your previous help

in basic the code would be

for x=1 to 100
Select Case
Case=10,20,30,40,50,60,70,80,90
then do this
else
else do this
end select
next x

how is this done in perl?

foreach (10,20,30,40,50,60,70,80,90);
{
do this;
}

???? I think I need to unpack my books! (i'm moving)LOL
Lou

Wiggins D Anconia
QUOTE
Hallo everyone and thank you for your previous help

in basic the code would be

for x=1 to 100
Select Case
Case=10,20,30,40,50,60,70,80,90
then do this
else
else do this
end select
next x

how is this done in perl?

foreach (10,20,30,40,50,60,70,80,90);
{
do this;
}

???? I think I need to unpack my books! (i'm moving)LOL
Lou


Well there is the FAQ about case statements:

perldoc -q 'switch or case'

In your case (pun intended) assuming the list is formed as you have it,
then you could do,

foreach my $index (1 .. 100) {
unless ($index % 10) {
# multiple of ten
}
else {
# not a multiple of ten
}
}

If your matches are not quite so nice,

my @list = (1, 15, 23, 67, 89);
foreach my $index (1 .. 100) {
if (grep $index == $_, @list) {
# case matched
}
else {
# non match
}
}

All code untested, HTH,

http://danconia.org

Ricardo Signes
* Luinrandir Hernsen <[Email Removed]> [2004-01-23T09:38:12]
QUOTE
Hallo everyone and thank you for your previous help

in basic the code would be
Select Case
...
end select

how is this done in perl?

Well, this is a common question. In fact, it's a frequently asked one
with an entry in the perlfaq. This kind of construct is called, in many
languages, a switch. You can see the FAQ's answer by running "perldoc
-q switch" or by looking for the switch/case question in perlfaq7.

Your example was specific, so I can give a specific answer or two:

for (1 .. 100) {
unless ($_ % 10) {
print "divisible by tenn";
}
}

That's about what you said, right? For every number from 1 to 100, do
something at the ten's. Of course, someone more familiar with C (or
with the syntax of 'for') might say:

for (my $i = 1; $i <= 100; $i+=10) {
print "$i is divisible by ten!n";
}

This skips a condition, incrementing $i by ten every time.

See, Perl was designed knowing that there are a whole lot of ways to use
a switch, and a whole lot of ways one might implement it specifically.
So, rather than canonize one, a single "switch" statement is left out.
The best thing to do is figure out how to solve the problem the best
way.

There does exist a module called Switch that will give you a switch/case
statement, but it's not really for production use. It's a neat idea,
but isn't ready for prime time.

Does that answer your question?

--
rjbs

Bob Showalter
Tim wrote:
QUOTE
At 03:16 PM 1/23/04 +0000, you wrote:
...
Why not write it yourself?

You need to know:

- Which day of the week is the 'first'.

- Which was the first week of the year that had four or more days.
That's week one.

Then do the sums/arithmetic/math/mathematics/calculations (what /do/
people prefer?)

.....
Rob

This message thread made me curious about just what constitutes the
first week of the year. Is there a standard definition or are we
making one here?

Tim

ISO8601 defines a standard, but not everyone follows it. See:

http://www.mcs.vuw.ac.nz/technical/softwar...01/ISO8601.html

Excerpt:

"An ordinal date is identified by a given day in a given year. A week is
identified by its number in a given year. A week begins with a Monday, and
the first week of a year is the one which includes the first Thursday, or
equivalently the one which includes January 4."

Here's January, 2004:

$ cal 1 2004
January 2004
Su Mo Tu We Th Fr Sa
1 2 3
4 5 6 7 8 9 10
11 12 13 14 15 16 17
18 19 20 21 22 23 24
25 26 27 28 29 30 31

Since weeks start on Monday, the week ending on Sunday, January 4 was week
1.

The DateTime family of modules on CPAN supports this standard.

Rob Dixon
Bob Showalter wrote:
QUOTE

ISO8601 defines a standard, but not everyone follows it. See:

http://www.mcs.vuw.ac.nz/technical/softwar...01/ISO8601.html

Excerpt:

"An ordinal date is identified by a given day in a given year. A week is
identified by its number in a given year. A week begins with a Monday, and
the first week of a year is the one which includes the first Thursday, or
equivalently the one which includes January 4."

Here's January, 2004:

$ cal 1 2004
January 2004
Su Mo Tu We Th Fr Sa
1  2  3
4  5  6  7  8  9 10
11 12 13 14 15 16 17
18 19 20 21 22 23 24
25 26 27 28 29 30 31

Since weeks start on Monday, the week ending on Sunday, January 4 was week
1.

The DateTime family of modules on CPAN supports this standard.

Thanks Bob. It's always nice to have a document to prod.

Strange though, since

QUOTE
A week begins with a Monday

yet the tabulation starts on Sunday.

Rob

Levon Barker
Except that John's boss is on the list too!

On Fri, 2004-01-23 at 14:37, John McKown wrote:
QUOTE
Unfortunately, if the person is writing from work, the disclaimer is
likely required by his employer. I know that I have a similar one at work.
And not including it is grounds for termination <stupid>.

The only way around this is to use a personal email, like I do. But he may
need the help for work and at work. Supposedly, I cannot use my personal
email from work. But I know ways and means around it and am stealthy
enough that I am not likely to get caught.

I'm sitting at work now, but using my home email.

--
Maranatha!
John McKown



John McKown
On Fri, 23 Jan 2004, Levon Barker wrote:

QUOTE
Except that John's boss is on the list too!


No, my boss is not UNIX or even Windows literate. He is a BOSS, not a
GRUNT. He may, from years past, remember some COBOL (remember that?). If I
told him that I was on a Perl list, he would think that I was talking
about the things that come out of oysters.

--
Maranatha!
John McKown

Mallik
Dear Friends,

I need to write a Perl CGI script that connects to
a website (like Yahoo) and change the Password for
my user. I don't want to do it manually. It should
be handled by the script.

Please suggest any idea/code available.

Thanks in advance,
Mallik.

Mallik
Dear Friends,

I need to write a Perl CGI script that connects to
a website (like Yahoo) and change the Password for
my user. I don't want to do it manually. It should
be handled by the script.

Please suggest any idea/code available.

Thanks in advance,
Mallik.

Mallik
Dear Friends,

I need to write a Perl CGI script that connects to
a website (like Yahoo) and change the Password for
my user. I don't want to do it manually. It should
be handled by the script.

Please suggest any idea/code available.

Thanks in advance,
Mallik.

Dan Muey
QUOTE
Dear Friends,

I need to write a Perl CGI script that connects to
a website (like Yahoo) and change the Password for
my user. I don't want to do it manually. It should
be handled by the script.


I've done similar thigns using LWP::UserAgent to log in and
submit forms with certain data.
That's where I'd look first.

HTH

DMuey

QUOTE
Please suggest any idea/code available.

Thanks in advance,
Mallik.

--
To unsubscribe, e-mail: [Email Removed]
For additional commands, e-mail: [Email Removed]
<http://learn.perl.org/> <http://learn.perl.org/first-response


Charles K. Clarkson
Mallik <[Email Removed]> posted this reply:
:
: : -----Original Message-----
: : From: Mallik [mailto:[Email Removed]]
: : Sent: Tuesday, January 27, 2004 5:26 AM
: : To: Perl Beginners
: : Subject: Automated script to connect to a web site and change
: : the Password
: :
: : Dear Friends,
: :
: : I need to write a Perl CGI script that connects to
: : a website (like Yahoo) and change the Password for
: : my user. I don't want to do it manually. It should
: : be handled by the script.
: :
: : Please suggest any idea/code available.
:
:
: Dear Friends,
:
: I need to write a Perl CGI script that connects to
: a website (like Yahoo) and change the Password for
: my user. I don't want to do it manually. It should
: be handled by the script.
:
: Please suggest any idea/code available.
:
: Thanks in advance,
: Mallik.


You emailed three messages to two email newsgroups asking the
same question and then you replied with the same exact message
again to each of those messages. In all there are six messages
cross posted to two email newsgroups (that I know of) to ask one
question.

What are thinking???

Charles K. Clarkson
--
Head Bottle Washer,
Clarkson Energy Homes, Inc.
Mobile Home Specialists


Peter Scott
In article <[Email Removed]>,
[Email Removed] (Mallik) writes:
QUOTE
Dear Friends,

I need to write a Perl CGI script that connects to
a website (like Yahoo) and change the Password for
my user. I don't want to do it manually. It should
be handled by the script.

Please suggest any idea/code available.

http://search.cpan.org
Mail::Webmail::Yahoo
WWW::Mechanize

--
Peter Scott
http://www.perldebugged.com/
*** NEW *** http//www.perlmedic.com/

Larry Snider
"John McKown" <[Email Removed]> wrote in message
news:[Email Removed]...

QUOTE
Except that John's boss is on the list too!


I don't know about John's boss but I'm not even on "the list." I'm reading
this in a newsgroup via GigaNews.


--
www.eSnider.net

John McKown
Sorry if this is a repost, but I haven't seen it come across the list and
I did have some problems with my mail server when I originally tried to
post it.


What is happening is that once a file has been opened, the handle points
to the "inode" which is an internal "number". This "number" is unique for
a filesystem and identifies the file regardless of its "name" in the
directory. That is why your Perl program is "following" the "old name".
Anyway,

What you need to do is create an entry in /etc/logrotate.d. Look at one of
the entries in there for an example of how to code it. Oh, I think you've
already done this.

What your Perl program needs to do is:

1) write its PID to a known location. Many put this is /var/run. Something
like:

open (PIDFILE,">/var/run/myPerlScript.pid") or die "cannot open pid file
$!";
print PIDFILE "$$";
close(PIDFILE);
....

2) Determine the "signal" that you want logrotate to issue to tell your
script to reopen its log file. Many programs use the HUP signal. Create a
signal handler in your Perl program to field this signal to close and
reopen its log file. This is the main "magic" to get this working. I'd
make LOGHANDLE an "our" variable at the top of the Perl program. Replace
LOGHANDLE with the correct variable, of course <grin>.

$SIG{HUP} = sub {
close(LOGHANDLE);
open(LOGHANDLE,">/var/log/myPerlScript.log") or die "cannot open
logfile $!";
};

3) Create the aforementioned logrotate entry in /etc/logrotate.d something
like:

/var/log/myPerlScript.log {
notifempty
missingok
postrotate
/usr/bin/kill -HUP `cat /var/run/myPerlScript.pid
QUOTE
/dev/null` 2>/dev/null || true
endscript

}

perhaps calling it "myPerlScript.log". Note - replace "myPerlScript" with
the actual name of your Perl script. Note that when the signal handler
actually executes, the previous myPerlScript.log file has already been
renamed, so the open in the signal handler create a new file with the old
name.


On Thu, 29 Jan 2004, TeamSolCO wrote:

QUOTE
I have written a long running perl application to help me with some
trivial administrative functions.  Due to the
volume of logging generated by this application, I am managing its
output with logrotate.  The problem I face is that
perl is "following" the log files that logrotate swaps out.  While this
is probably intelligent on perl's part (to
follow the file descriptor rather than the file name), it is presenting
a major problem for me.  When "logfile" becomes
"logfile.1" (etc), my application follows that move and "continues"
logging to the new "logfile.1" instead of losing
that file handle -- a condition which I check for so that I can reopen
the log file using the proper file name,
"logfile".
Ultimately, perl will only lose the file handle when logrotate
finally deletes the "last file" in the log rotation
scheme.  Unfortunately, I will have lost a week's worth of logs
because all that data will have been in the single file.
Additionally, I'll have several empty log file copies named .1, .2, .3,
etc.  How can I set perl to NOT follow the file
when it is renamed by logrotate, such that a condition will be created
where I will be able to initialize the
replacement file?

Thanks!!

- William Kimball
"Programming is an art-form that fights back!"


--
Maranatha!
John McKown

Lonewolf
Nedit
http://nedit.org/

Macros can be found here if they are not already there (nedit comes with a
LOT of them already)
http://www.google.com/search?sourceid=navc...e=UTF-8&q=nedit

HTH
Robert


QUOTE
On Fri, 30 Jan 2004 08:32:02 -0700 Wiggins d Anconia <[Email Removed]
wrote.

Is there a visual perl editor out there, freeware or shareware for any
Linux flavor?


perldoc -q 'IDE or Windows Perl Editor'

Since I use Vim the closest for me would be gvim.

http://danconia.org

--
To unsubscribe, e-mail: [Email Removed]
For additional commands, e-mail: [Email Removed]
<http://learn.perl.org/> <http://learn.perl.org/first-response



John McKown
On Sat, 31 Jan 2004, John W. Krahn wrote:

<snip>
QUOTE
use POSIX 'mkfifo';

die "Cannot initialize $path_fifo: $!"
unless unlink $path_fifo and mkfifo $path_fifo and chmod 0600,
$path_fifo;


Just one, very minor "improvement", of the above might be:

die "Cannot initialize $path_fifl: $!"
unless unlink $path_fifo and mkfifo($path_info,0600);

Granted, this is a nit, but if in a loop which executes a million times,
it could add up. I guess that I've been on "CPU constrained" systems for
so long that every millisecond is now precious <grin>.

--
Maranatha!
John McKown

Rob Hanson
QUOTE
but I can not retrieve the data into $newline with join. Is this bit wrong

Yes, it is a little off.

QUOTE
$member_array[$count]

This *isn't* an array, it is an *array reference*

QUOTE
[@edit_array]

Same with this.

Join takes a list of scalars, not a list of references. So you need to
dereference them. I think this is what you are after.

join(":",@{$member_array[$count]});

Rob


-----Original Message-----
From: Support [mailto:[Email Removed]]
Sent: Sunday, February 01, 2004 2:31 PM
To: [Email Removed]
Subject: Writing to file

Hi all
I have a little bit of code you may be able to help with. I load a file into
an array with

foreach $lines(@database_array) {
@edit_array = split(/:/,$lines);
push(@member_array,[@edit_array]);
$x++;
} #loop

and then play around with the array a bit, then I would like to load it back
into the file with

while($count<$x){
$newline = join(":",$member_array[$count],[@edit_array]);
chomp($newline);
print DAT "$newlinen";
$count++;
}

but I can not retrieve the data into $newline with join. Is this bit wrong

$member_array[$count],[@edit_array])

or am I missing the point completely or is there another way of doing it.
I am currently loading direct from the file working on that line and them
loading back to file, but I can only change one line at a time. Doing it
with as above I can alter the entire array and then load back to file.
Any help is appreciated and please excuse if I'm in the wrong forum.
Cheers
Colin
----------------------------------------------------------------------------
-------------------

www.rentmyplace.co.nz
The ultimate in that holiday spot away from the maddening crowd
Join as a member today its FREE
List your holiday accommodation for FREE
----------------------------------------------------------------------------
--------------------

Dennis G. Wicks
Greetings;

I have a file that I need to sort and currently I am just
sorting it by

@datalist = sort(@datalist);

but it will eventually have many more records and many of
them may be quite large, but I only need to sort on the
first six characters which would be faster. Wouldn't it?

I have looked at perldoc and it shows things like

@articles = sort {$a <=> $b} @files;

but I can't figure out how to tell the sort that $a and $b
are the first six characters of @datalist. That is numeric
data BTW.

Any help or pointers appreciated.

Dennis

Dennis G. Wicks
Thanks Eric.

But, although some dates may be six digits and some six
digit numbers may be dates, that isn't the case here. ;-)

It is a sequence number that is previously generated/changed
to get the records in the correct sequence for reporting.

Dennis


On Mon, 2 Feb 2004, Eric Edwards wrote:

QUOTE
Date: Mon, 2 Feb 2004 14:14:31 -0600
From: Eric Edwards <[Email Removed]
To: Dennis G. Wicks <[Email Removed]>, [Email Removed]
Subject: Re: Need help sorting by specific fields in file.

Dennis,
Not to tell you how to run your business, but how is the date formatted in
the array?
It has been my experience in working with dates that they should be
formatted as 20040202.  This allows you to sort on years that are different.
Eric
----- Original Message -----
From: "Dennis G. Wicks" <[Email Removed]
To: <[Email Removed]
Sent: Monday, February 02, 2004 1:49 PM
Subject: Need help sorting by specific fields in file.


Greetings;

I have a file that I need to sort and currently I am just
sorting it by

@datalist = sort(@datalist);

but it will eventually have many more records and many of
them may be quite large, but I only need to sort on the
first six characters which would be faster. Wouldn't it?

I have looked at perldoc and it shows things like

@articles = sort {$a <=> $b} @files;

but I can't figure out how to tell the sort that $a and $b
are the first six characters of @datalist. That is numeric
data BTW.

Any help or pointers appreciated.

Dennis


--
To unsubscribe, e-mail: [Email Removed]
For additional commands, e-mail: [Email Removed]
<http://learn.perl.org/> <http://learn.perl.org/first-response




Eric Edwards
Dennis,
Not to tell you how to run your business, but how is the date formatted in
the array?
It has been my experience in working with dates that they should be
formatted as 20040202. This allows you to sort on years that are different.
Eric
----- Original Message -----
From: "Dennis G. Wicks" <[Email Removed]>
To: <[Email Removed]>
Sent: Monday, February 02, 2004 1:49 PM
Subject: Need help sorting by specific fields in file.


QUOTE
Greetings;

I have a file that I need to sort and currently I am just
sorting it by

@datalist = sort(@datalist);

but it will eventually have many more records and many of
them may be quite large, but I only need to sort on the
first six characters which would be faster. Wouldn't it?

I have looked at perldoc and it shows things like

@articles = sort {$a <=> $b} @files;

but I can't figure out how to tell the sort that $a and $b
are the first six characters of @datalist. That is numeric
data BTW.

Any help or pointers appreciated.

Dennis


--
To unsubscribe, e-mail: [Email Removed]
For additional commands, e-mail: [Email Removed]
<http://learn.perl.org/> <http://learn.perl.org/first-response



James Edward Gray II
On Feb 2, 2004, at 1:49 PM, Dennis G. Wicks wrote:

QUOTE
Greetings;

I have a file that I need to sort and currently I am just
sorting it by

@datalist = sort(@datalist);

Okay, but you're not sorting a file there. You're sorting an array.
Maybe that array was loaded from a file, but we're dealing with in
memory arrays now.

You mention below that this is numeric data, so that should be:

@datalist = sort { $a <=> $b } @datalist;

QUOTE
but it will eventually have many more records and many of
them may be quite large, but I only need to sort on the
first six characters which would be faster. Wouldn't it?

Honestly, I don't know, but I suspect that it wouldn't. I could be
wrong. You could benchmark to find out. Thing is, first you have to
grab the first 6 characters off of all of them, that takes time.
You're also assuming that the default comparison, whatever it is, is
comparing every single character. I would hope it sort circuits as
soon as it has enough information to compare things. If it does, you
might slow it down, instead of speed it up.

More importantly, this is a problem to consider AFTER it becomes slow.
You say it's fast now. Great. Don't touch it. Computers can handle a
lot of information very fast these days and humans who spend time
coding a "faster" solution for something that was already happening in
the blink of an eye are silly.

My worry, just from reading your message, was: Is the dataset too big
to be placed into a single array in memory, as it seems you are doing?

QUOTE
I have looked at perldoc and it shows things like

@articles = sort {$a <=> $b} @files;

but I can't figure out how to tell the sort that $a and $b
are the first six characters of @datalist. That is numeric
data BTW.

Any help or pointers appreciated.

@dataset = sort { substr($a, 0, 6) <=> substr($b, 0, 6) } @dataset;

That's just a basic grab the first 6 numbers and compare approach. For
big data sets though, we can possibly get faster:

@dataset =
map { $$_[1] }
sort { $$a[0] <=> $$b[0] }
map { [ substr($_, 0, 6), $_ ] } @dataset;

That's a little trickier. First, we build a list of all the sub
strings, then we compare, then we restore the original, but now sorted
list. Usually, this is faster, if a sort has complex transformations
needed to compare data and the list is big. However, I'm not sure how
much faster a dereference for those array refs I used is going to be
over a substr() call.

Again, you would have to benchmark to see if we're making any
meaningful gains here, which I'm doubtful of. Perl includes a standard
Benchmark module for this.

I hope that helps.

James


PHP Help | Linux Help | Web Hosting | Reseller Hosting | SSL Hosting
This is a "lo-fi" version of our main content. To view the full version with more information, formatting and images, please click here.
Invision Power Board © 2001-2006 Invision Power Services, Inc.