Re: regular expressions

2003-01-10 Thread John W. Krahn
Evan N Mr Niso/Lockheed Martin Kehayias wrote:
> 
> Greetings,

Hello,

> I am attempting to limit entries a user could make when inputting names into
> one of my scripts.  I prompt the user to enter one or more names.  One name
> is easy to isolate but when there are more I want to support commas.  At the
> same time I don't want to accept anything other than names and commas.  I
> want to force the user to either enter names correctly or exit.  For that
> matter it would be really cool if I could test the names against
> /etc/passwd.

You can.

$ perl -le'
if ( defined( getpwnam( $ARGV[0] ) ) ) {  
print "$ARGV[0] found";
} 
else {
print "$ARGV[0] NOT found";
} 
' root
root found
$ perl -le'
if ( defined( getpwnam( $ARGV[0] ) ) ) {
print "$ARGV[0] found";
}
else {
print "$ARGV[0] NOT found";
}
' fred
fred NOT found



John
-- 
use Perl;
program
fulfillment

-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]




Re: Top Posting Preferences (was navigate the directories)

2003-01-10 Thread John W. Krahn
Rob Dixon wrote:
> 
> Hi John, all

Hello,

> "John W. Krahn" <[EMAIL PROTECTED]> wrote in message
> [EMAIL PROTECTED]">news:[EMAIL PROTECTED]...
> >
> > [ top-posting fixed ]
> 
> I'm wondering how much of an error, if any, people think this is? I
> personally choose to top-post so that anybody reading through a thread won't
> have to page to the end of each post to get to new content. Also end-posting
> can be missed by those who don't think to look there! I can find nothing in
> the group guidelines to support either method.
> 
> I'd like to do what people prefer so, comments please...?

The main problem with top-posting is that people click reply, type in
their reply, and then send, leaving all the previous posts at the bottom
which can add up to dozens or even hundreds of lines of irrelevant text.


John
-- 
use Perl;
program
fulfillment

-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]




Re: suppress STDIN from user

2003-01-10 Thread Rob Dixon
That's right. It's:

use Term::ReadKey;
:
ReadMode 2;
$pass = ReadLine 0;
ReadMode 0;


/R
"Simran" <[EMAIL PROTECTED]> wrote in message
1042162674.10277.43.camel@pingu">news:1042162674.10277.43.camel@pingu...
> Have a look at Term::ReadKey ...
>
> You need to set noecho (i think...)
>
>




-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]




Check if a hash is empty

2003-01-10 Thread NYIMI Jose (BMB)
Hello,

If(keys %hash){
#do ...
}

Could you suggest an other way, please ?

Thanks in advance.

José.


 DISCLAIMER 

"This e-mail and any attachment thereto may contain information which is confidential 
and/or protected by intellectual property rights and are intended for the sole use of 
the recipient(s) named above. 
Any use of the information contained herein (including, but not limited to, total or 
partial reproduction, communication or distribution in any form) by other persons than 
the designated recipient(s) is prohibited. 
If you have received this e-mail in error, please notify the sender either by 
telephone or by e-mail and delete the material from any computer".

Thank you for your cooperation.

For further information about Proximus mobile phone services please see our website at 
http://www.proximus.be or refer to any Proximus agent.




Re: Check if a hash is empty

2003-01-10 Thread Victor Tsang
if (%hash){
  $ do
}


Tor.

"NYIMI Jose (BMB)" wrote:
> 
> Hello,
> 
> If(keys %hash){
> #do ...
> }
> 
> Could you suggest an other way, please ?
> 
> Thanks in advance.
> 
> José.
> 
>  DISCLAIMER 
> 
> "This e-mail and any attachment thereto may contain information which is 
>confidential and/or protected by intellectual property rights and are intended for 
>the sole use of the recipient(s) named above.
> Any use of the information contained herein (including, but not limited to, total or 
>partial reproduction, communication or distribution in any form) by other persons 
>than the designated recipient(s) is prohibited.
> If you have received this e-mail in error, please notify the sender either by 
>telephone or by e-mail and delete the material from any computer".
> 
> Thank you for your cooperation.
> 
> For further information about Proximus mobile phone services please see our website 
>at http://www.proximus.be or refer to any Proximus agent.

-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]




Re: Check if a hash is empty

2003-01-10 Thread Rob Dixon
Hi

I'm wondering why you want another way, as this is slower than it needs to
be but shouldn't cause any problems, but you can just do:

if (%hash)
{
:
}

which is neater.

HTH,

Rob


"Nyimi Jose" <[EMAIL PROTECTED]> wrote in message
[EMAIL PROTECTED]">news:[EMAIL PROTECTED]...
> Hello,
>
> If(keys %hash){
> #do ...
> }
>
> Could you suggest an other way, please ?
>



-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]




Re: Help with end-time start-time sorting problem

2003-01-10 Thread John W. Krahn
Deborah Scott wrote:
> 
> I have a txt data file that has several fields. Two of the fields are start
> time and end time (listed in epoch time).
> 
> I need to write a perl program that finds (and prints) events that occur
> between midnight "last night" and "midnight tonight."
> 
> First problem:
> The date for midnight "last night" and "tonight" will change each day, so
> this needs to be some kind of automatic date finder.

use Time::Local;

my @today = localtime;  # get todays date and time
@today[0..2] = ( 0, 0, 0 );  # make it midnight
my $lastnight = timelocal( @today );  # convert to epoch time (seconds)
my $tonight = $lastnight + 86_400;


> Second problem:
> How do I find (and then list) only those events that occur TODAY.
> These events might start or stop at any time during the month.

if ( $event >= $lastnight and $event <= $tonight ) {
print "$event happened today.";
}


> The events that I would list would include ANYTHING that includes "today."
> Some might start today and end today and last only an hour. Some might start
> two days ago and end next week. This txt file will also list events that
> have already started and stopped last month or will start in the future, so
> I have to make sure that these are NOT included in "today's" report.

my $today = time;  # get epoch time

if ( $start_event < $today and $end_event > $today ) {
print "$event includes today.";
}




John
-- 
use Perl;
program
fulfillment

-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]




Re: Removing a specific value from a hash whose keys contains multiple values

2003-01-10 Thread John W. Krahn
Sophia Corwell wrote:
> 
> Sorry about that...
> 
> Here is an example:
> 
> Here is what my hash looks like:
> 
> %compilers = (
>system1 => ['compiler_a'],
>system2 => ['compiler_b',
> 'compiler_c','compiler_d'],
>system3 => ['compiler_e'],
> );
> 
> Now, if I want to delete just the 'compiler_c' value
> from the system2 key, can I use the delete function or
> the pop function?

If you know in advance the array index then use splice.

splice @{$compilers{'system2'}}, 1, 1;

If you have to delete based on the value then you should probably use
grep.

@{$compilers{'system2'}} = grep $_ ne 'compiler_c',
@{$compilers{'system2'}};



John
-- 
use Perl;
program
fulfillment

-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]




Re: Extracting Info from a websource

2003-01-10 Thread Sukrit

> "Rob" == Rob Dixon <[EMAIL PROTECTED]> writes:

Rob> Well, I'm not sure what to do here. It's quite possible - I
Rob> would use modules LWP, HTTP::Request::Form and
Rob> HTML::TreeBuilder - but if you've only just read LP then I
Rob> doubt you would understand how to do it. I could write the
Rob> code for you (which I'm happy to if you want) but that
Rob> wouldn't teach you anything. 


Sorry for the delayed reply, it's a time zones thing. Thanks for the
help/pointers. i found an article on LWP[1], will look through it and if i run into 
something i'll get back to you. 

Rob> If you can 'extract information
Rob> from an HTML page' does that mean you can retrieve it with
Rob> Perl?

It means that i can, if i have a locally saved copy of the said html
page "extract" information from it. However i have a problem "retrieving" it, that is, 
saving a local copy. 

Extraction part of the problem is very well covered in "Learning
Perl". For retrieving i would have to use LWP. Trying to pick up LWP from [1].

Rob> Over to you: how can I/we best help?

Thanks you already have, i just needed a roadmap. LWP is it i
think.


Rob> Rob

Sukrit
[1] http://www.perl.com/pub/a/2002/08/20/perlandlwp.html

Ps: Thought reply-to was set to the mailing list, so sorry if you got
a mail offlist.
 __
/  [EMAIL PROTECTED]  ||http://www.symonds.net/~holysmoke  \
|  GPG: 77D81FC4  9368 9352 BBF7 6390 0E40 FC88 5903 2CD5 77D8 1FC4|


-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]




Re: Top Posting Preferences (was navigate the directories)

2003-01-10 Thread Randal L. Schwartz
> "Wiggins" == Wiggins D'Anconia <[EMAIL PROTECTED]> writes:

Wiggins> How about top posting where it makes sense, aka the argument has
Wiggins> shifted substantially, the original poster had no clue what they were
Wiggins> talking about :-), etc.

In that case, it's a new thread.  Don't even hit reply.  Don't include
anything of the previous discussion.

So top-posting is *still* wrong there.

-- 
Randal L. Schwartz - Stonehenge Consulting Services, Inc. - +1 503 777 0095
<[EMAIL PROTECTED]> http://www.stonehenge.com/merlyn/>
Perl/Unix/security consulting, Technical writing, Comedy, etc. etc.
See PerlTraining.Stonehenge.com for onsite and open-enrollment Perl training!

-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]




checking if a file is empty

2003-01-10 Thread PRADEEP GOEL
Hi all
///
if($TYPE eq "HP-UX")
  {  `/usr/sbin/swlist | grep  "OV NNM" |cut -f1> RF1 `;}
else
  {  `find /system/ -name deins_patch |cut -f3 -d /  > RF1`; }

#
how to check if the  newly made file RF1 is empty or not ?
#
open(RFh1,"RF1") or die "Not able to open RF1 \ n";
  my @pachs =  ;
my($num3)  = $pachs[0]=~ /_(\d+)$/;

I want $num3 to be 0 if   RF1  is empty .


thanks & rgds
Pradeep


-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]




Re: checking if a file is empty

2003-01-10 Thread Sudarshan Raghavan



#
how to check if the  newly made file RF1 is empty or not ?
#



perldoc -f -x
check the -z operator



--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]




RE: regular expressions

2003-01-10 Thread Kehayias, Evan N Mr NISO/Lockheed Martin
At this point could a user still input something like 7mary3.  Ideally a
user can enter a name or several separated by commas but *nothing* else.
Convention would be lowercase firstinitiallastname  It seems like Rob's is
really close but I don't understand all of the code.  I am a little shy with
arrays.  Is @names built as you go? And, is the input all one element? It
seems to me as if that is the case but not 100% sure.


-Original Message-
From: Rob Dixon [mailto:[EMAIL PROTECTED]]
Sent: Thursday, January 09, 2003 10:43 AM
To: [EMAIL PROTECTED]
Subject: Re: regular expressions


Hi Paul

See below.

"Paul Kraus" <[EMAIL PROTECTED]> wrote in message
021b01c2b7f3$490ed540$64fea8c0@pkrausxp">news:021b01c2b7f3$490ed540$64fea8c0@pkrausxp...
> Correct me if I am wrong but wouldn't
> @names = sprit /,/,$ans;

That's pretty much what I did, except that I added optional leading and
trailing whitespace to the regex so that these would be trimmed from the
names. I didn't actually do the job properly though, because whitespace at
the start and end of $ans won't be removed, and input like '   Henrietta'
will fail. Nearly right though!

> Then you could perform your tests against the array elements.
> if (/[A-Za-z]+/)

Not really. That only checks to see if the name contains at least one alpha.
I did {/[^a-zA-Z]/ which checks for at least one non-alpha, when the loop
continues and reports an error. Also you don't need the '+' modifier.

> Assuming that the names would only contain those characters.
>
> or if (/\w+/) meaning all word characters.

/\W/ would do in my code, but its unwholesome inclusion of the underscore in
a valid 'word' character makes it much less useful for non-programming apps.

>
> Do the same thing. Splitting everything separated by a comma?

Unsure what you mean here :-? I'll pretend you didn't say it.

Cheers,

Rob

>
> > -Original Message-
> > From: Rob Dixon [mailto:[EMAIL PROTECTED]]
> > Sent: Thursday, January 09, 2003 10:06 AM
> > To: [EMAIL PROTECTED]
> > Subject: Re: regular expressions
> >
> >
> > Hello, erm, "Evan N Mr Niso/Lockheed Martin Kehayias"
> >
> > This should do what you want:
> >
> >
> > my @names;
> > do {
> > errmesg() if @names;
> > my $ans = ;
> > @names = split /\s*,\s*/, $ans;
> > } while (grep {/[^a-zA-Z]/} @names);
> >
> > which splits on commas with any amount of preceding and
> > trailing whitespace. Names have to be alphabetic.
> >
> > HTH,
> >
> > Rob
> >
> >
> > "Evan N Mr Niso/Lockheed Martin Kehayias"
> > <[EMAIL PROTECTED]> wrote in message
> > 90AFE0B84E52EE46A8CD1DB0789C0A860ED043@DADC144">news:90AFE0B84E52EE46A8CD1DB0789C0A860ED043@DADC144...
> > > Greetings,
> > >
> > > I am attempting to limit entries a user could make when inputting
> > > names
> > into
> > > one of my scripts.  I prompt the user to enter one or more
> > names.  One
> > name
> > > is easy to isolate but when there are more I want to
> > support commas.
> > > At
> > the
> > > same time I don't want to accept anything other than names
> > and commas.
> > > I want to force the user to either enter names correctly or
> > exit.  For
> > > that matter it would be really cool if I could test the
> > names against
> > > /etc/passwd.  But beggars can't be choosers I will tackle the array
> > > piece later.
> > >
> > > What the user sees:
> > >
> > > Please enter user name(s):
> > > If more than one separate using commas
> > > example (single name): evan
> > > example (multi name): debbie, clint, henry
> > >
> > >
> > >
> > > So far what broken pieces I have...
> > >
> > > #!/usr/bin/perl
> > >
> > >
> > > while($ans !~ /^[a-z]+$/ || $ans !~ /^[a-z]+\,?[a-z]*$/) {
> > >   errmesg ();
> > >   $ans = ;
> > >
> > > };
> > >
> > > sub errmesg {
> > >   print "\nType user name(s) and press enter:\n";
> > >   print "note: if more than one separate using commas\n";
> > >   print "example (single name): evan\n";
> > >   print "example (multi name): debbie, clint, henry\n";
> > > }
> > >
> >
> >
> >
> > --
> > To unsubscribe, e-mail: [EMAIL PROTECTED]
> > For additional commands, e-mail: [EMAIL PROTECTED]
> >
>



-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]



Re: CRLF vs LF questions

2003-01-10 Thread David Eason
HTML-Kit will do that, too. It's just that I have been known to open up
lesser editors from time to time, such as Notepad.

I'll check with my ISP to see if  the Perl on the Cobalt Raq's can be
upgraded. It doesn't matter that much, though.

Thanks for the replies.




-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]




RE: regular expressions

2003-01-10 Thread Kehayias, Evan N Mr NISO/Lockheed Martin
What I posted earlier is pretty much it.  I basically want to change the
contents of a sudoers file for sudo.  I make almost all of the other
modifications in another script.  In the current script I want to find the
line that says  User_AliasACLPUSHER in the sudoers file and replace it
with itself and append = user1, user2, user3.  Of course users 1 through 3
are relative to the operator input. The line I am searching for is:
 
User_AliasACLPUSHER = test1, test2#where test1 and test2 may vary
 
Okay I am pretty lame... I have a line in there using sed but I will change
it before I am done.  But basically I find the line User_Alias.*ACLPUSHER
and replace it.
 
 
 #!/usr/bin/perl 
while($ans !~ /^[a-z]+$/ || $ans !~ /^[a-z]+\,?[a-z]*$/) { 
   errmesg (); 
  $ans = ; 
}; 

 `sed 's/^\(User_Alias.*ACLPUSHER\).*/\1 = '"$NAME"'/' s2`;

 sub errmesg { 
   print "\nType user name(s) and press enter:\n"; 
   print "note: if more than one separate using commas\n"; 
   print "example (single name): evan\n"; 
   print "example (multi name): debbie, clint, henry\n"; 
} 

Thanks again for your help,
Evan
 
P.S. Do you know if there is an ettiquette or rules page for this list?  I
have received mail from it for a long time but haven't posted much.  
 
 

-Original Message-
From: Paul Kraus [mailto:[EMAIL PROTECTED]]
Sent: Thursday, January 09, 2003 11:07 AM
To: Kehayias, Evan N Mr NISO/Lockheed Martin
Subject: RE: regular expressions


split takes an line and splits it by deliminator (perldoc -f split)
 
so if your input was
 
paul, david, kraus\n
 
then $names[0]="paul"
   $names[1]=" david" #notice the space.
   $names[2]=" kraus\n" #notice the new line. If you did not want the
new line make sure you chomp your input.
 
Why don't you post your script so far so we have a better idea of what your
trying to do.

-Original Message-
From: Kehayias, Evan N Mr NISO/Lockheed Martin
[mailto:[EMAIL PROTECTED]] 
Sent: Thursday, January 09, 2003 11:00 AM
To: [EMAIL PROTECTED]
Cc: 'Rob Dixon'; 'Paul Kraus'
Subject: RE: regular expressions



At this point could a user still input something like 7mary3.  Ideally a
user can enter a name or several separated by commas but *nothing* else.
Convention would be lowercase firstinitiallastname  It seems like Rob's is
really close but I don't understand all of the code.  I am a little shy with
arrays.  Is @names built as you go? And, is the input all one element? It
seems to me as if that is the case but not 100% sure.


-Original Message- 
From: Rob Dixon [ mailto:[EMAIL PROTECTED]
 ] 
Sent: Thursday, January 09, 2003 10:43 AM 
To: [EMAIL PROTECTED] 
Subject: Re: regular expressions 


Hi Paul 

See below. 

"Paul Kraus" <[EMAIL PROTECTED]> wrote in message 
021b01c2b7f3$490ed540$64fea8c0@pkrausxp">news:021b01c2b7f3$490ed540$64fea8c0@pkrausxp
<021b01c2b7f3$490ed540$64fea8c0@pkrausxp">news:021b01c2b7f3$490ed540$64fea8c0@pkrausxp> ... 
> Correct me if I am wrong but wouldn't 
> @names = sprit /,/,$ans; 

That's pretty much what I did, except that I added optional leading and 
trailing whitespace to the regex so that these would be trimmed from the 
names. I didn't actually do the job properly though, because whitespace at 
the start and end of $ans won't be removed, and input like '   Henrietta' 
will fail. Nearly right though! 

> Then you could perform your tests against the array elements. 
> if (/[A-Za-z]+/) 

Not really. That only checks to see if the name contains at least one alpha.

I did {/[^a-zA-Z]/ which checks for at least one non-alpha, when the loop 
continues and reports an error. Also you don't need the '+' modifier. 

> Assuming that the names would only contain those characters. 
> 
> or if (/\w+/) meaning all word characters. 

/\W/ would do in my code, but its unwholesome inclusion of the underscore in

a valid 'word' character makes it much less useful for non-programming apps.


> 
> Do the same thing. Splitting everything separated by a comma? 

Unsure what you mean here :-? I'll pretend you didn't say it. 

Cheers, 

Rob 

> 
> > -Original Message- 
> > From: Rob Dixon [ mailto:[EMAIL PROTECTED]
 ] 
> > Sent: Thursday, January 09, 2003 10:06 AM 
> > To: [EMAIL PROTECTED] 
> > Subject: Re: regular expressions 
> > 
> > 
> > Hello, erm, "Evan N Mr Niso/Lockheed Martin Kehayias" 
> > 
> > This should do what you want: 
> > 
> > 
> > my @names; 
> > do { 
> > errmesg() if @names; 
> > my $ans = ; 
> > @names = split /\s*,\s*/, $ans; 
> > } while (grep {/[^a-zA-Z]/} @names); 
> > 
> > which splits on commas with any amount of preceding and 
> > trailing whitespace. Names have to be alphabetic. 
> > 
> > HTH, 
> > 
> > Rob 
> > 
> > 
> > "Evan N Mr Niso/Lockheed Martin Kehayias" 
> > <[EMAIL PROTECTED]> wrote in message 
> > 90AFE0B84E52EE46A8CD1DB0789C0A860ED043@DADC144">news:90AFE0B84E52EE46A8CD1DB0789C0A860ED043@DADC144
<90AFE0B84E52

Removing a specific value from a hash whose keys contains multiple values

2003-01-10 Thread Sophia Corwell
I am not sure how to delete a specific value from a
hash whose keys contains multiple values.

Could anyone advice, please?

Thanks,

Sophia

__
Do you Yahoo!?
Yahoo! Mail Plus - Powerful. Affordable. Sign up now.
http://mailplus.yahoo.com

-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]




Best way to return largest of 3 Vars?

2003-01-10 Thread Tim Musson
Hey all,

  I need to return the largest of 3 vars. Is there a better way than
  nested IF statements? Maybe put them in an array and sort it?

-- 
Tim Musson
Flying with The Bat! eMail v1.62 Christmas Edition
Windows 2000 5.0.2195 (Service Pack 2)
Why isn't there mouse-flavored cat food?


-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]




Re: Perl Subroutines

2003-01-10 Thread Bob X

"Joshua Scott" <[EMAIL PROTECTED]> wrote in message
5D23931127B7EB409640001B7E8A6E32014A2AFA@PASNT32">news:5D23931127B7EB409640001B7E8A6E32014A2AFA@PASNT32...
> I've created a group of Perl subroutines to handle the creation and layout
> of my web pages.  These subs are used when browsing to my website.
> Basically all they do when invoked is print a bunch of HTML.  I've now run
> into the scenario where I'd like to use these same subs to print static
web
> pages where the output doesn't go to the web browser, but instead goes to
a
> file.  How could I go about doing that?
>
> Here's an example of what my subs look like:
>
> Sub opentbl {
> Print "";
> Print "";
> Print "";
> Print "";
> Print "";
> };
>
> I call the sub from webpages the standard way.
>
> I sure hope I explained this clearly.  I'm still getting used to Perl.
> Thank you for any help you can provide!
>
> Joshua Scott
>
>
Not sure from the web but I do this:

sub web_file {
open(WEB_FILE, ">>filename.txt") || die "Unable to open $!";
print WEB_FILE "";
print WEB_FILE "";
print WEB_FILE "";
print WEB_FILE "";
print WEB_FILE "";
close( WEB_FILE);
}

You may be better served putting the text file in a variable like:

my $web_file = "path/to/file/filename.txt";

This is off the cuff. I know the sub works from the prompt since I use
it onWindows to create batch files on the fly.

Hope this helps...or at least gives you an idea.

Bob



-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]




Re: Top Posting Preferences (was navigate the directories)

2003-01-10 Thread Bob X
"R. Joseph Newton" <[EMAIL PROTECTED]> wrote in message
[EMAIL PROTECTED]">news:[EMAIL PROTECTED]...

Having perused a few newsgroups I would say that 99.9% of them post to the
bottom of the e-mail. Question at the top...answers at the end.

Bob



-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]




Re: Extracting Info from a websource

2003-01-10 Thread Kieren Diment
On Fri, Jan 10, 2003 at 12:51:45AM +0530, Sukrit wrote:

> Problem Overview
> - 
> Somewhere on the world wide web, exists an asp page with the following
> form -
> 

> 
> On entering a valid roll number and pressing enter, results for that number
> are displayed. Currently this has to be done manually, for say 120
> students. Very painful indeed.
> 
> 1 What i can manage
> - ---
> i can,
> 1.1 Generate valid numbers.
> 1.2 Extract information from an html page.
> 
> 2 What i need to know
> - -
> i need to know how to,
> 2.1 Enter info in a form at a particular url.
> 2.2 Save the resultant file on locally. (for 1.2 above)
> 

I see that you are a unix user (probably):

X-Mailer: VM 7.07 under 21.4 (patch 6) "Common Lisp" XEmacs Lucid

Here's how I'd do it.

Using the lynx web browser I would go to the site of interest, enter some
information into the form , select the submit button and press =

This gives me some information about what is happening to the url
ie. what information is getting POSTed and what is getting GETed

then I'll use LWP::Simple to send appropriate requests and pop them in
a suitable file.

Here's something to do something similar (untested):

#!/usr/bin/perl -w
my $file="";
open  $file;
use strict ;
use LWP::UserAgent;
my $ua = LWP::UserAgent->new;
my $req;
my $url=""
my $res;
my $request_string="";
$req = HTTP::Request->new(POST => $url);
$req->content_type('application/x-www-form-urlencoded');
$req->content($request_string);
$res = $ua->request($req);
my $result =  $res->as_string; # or other appropriate method as you desire.
print FILE $result;


or similar.  man lwpcook should tell you more.  I suspect that there
are mistakes in my code, but that should get you started.

Kieren

-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]




Re: Remove some, not all \n from a text block

2003-01-10 Thread Alan C.
John W. Krahn wrote:

"Alan C." wrote:



Here is one way to do it:

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

my $text = do { local $/; <> };
$text =~ s/\n(?!\.|\z)/ /g;
print $text;


Your code does the job just super! Thanks!
The (|) parenthesis "group" with left side | right side sandwiched 
between the parenthesis
The | means "or" right?
then \z means end of string (end of my entire small amount of text)
According to MRE2, the ?! is a fail-look ahead position matcher of sorts 
that enables a match-fail combo characteristic so all possible matches 
are returned?

I'm too new.  But, regexes for me to new heights with more study/practice!

--
Alan.


--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]



Re: Remove some, not all \n from a text block

2003-01-10 Thread Alan C.
Rob Dixon wrote:


my $last = undef;

while (<>)
{
next unless defined $last;
chomp $last unless /^\./;
print $last;
} continue {
$last = $_;
}

print $last;


Your code works super for the job!

I had thought of chomp and unless.  But I'm too new, didn't know how to 
implement them.

Just to take yours apart, my trying to understand it, I thought next 
would work.

while (<>) {
chomp unless m/^\./;
print "$_";
  }

But I tried it.  It does not work, and I don't know why.

perldoc -q continue turned up nothing.

I understand the regex part of your code--looks like that line of code 
means "chomp the line if it is a line that does not begin with a period"

The first iteration, $last is not defined therefore next will make it 
what (try on the next line of my text that's my guess)(therefore when 
$last is undef it doesn't chomp but instead trys/begins on the next line 
of my text)

providing condition met, "next" makes it skip to the next iteration?

I don't understand the workings of 1. how it might potentially go from 
undef to defined  2. what the continue does or how it works

Is there a documentation to help me understand it or would you explain it?

Meanwhile I'll be continuing my studies/practice with "Learning Perl 
3rd" and later I'll reference "Programming Perl 3rd" on continue and undef

--
Alan.


--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]



Re: Removing a specific value from a hash whose keys contains multiple values

2003-01-10 Thread Tim Musson
Hey Sophia, 

My MUA believes you used 
to write the following on Thursday, January 9, 2003 at 6:48:42 PM.

SC> I am not sure how to delete a specific value from a hash whose
SC> keys contains multiple values.

SC> Could anyone advice, please?

Does this help?

perldoc -q delete

-- 
Tim Musson
Flying with The Bat! eMail v1.62 Christmas Edition
Windows 2000 5.0.2195 (Service Pack 2)
Your mouse has moved. Windows must now reboot. Click OK to continue.


-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]




Re: Delimiter Question

2003-01-10 Thread Mark Goland
> How do I challenege more than one variable like I want to 
>  check for the input of Y N y or n for a yes no question. I 
>  put until $answer =~ m/YyNn/ that did not work. Anybody have 
> any solutions?

the way you did it, would need to use or operator
$answer =~ m/Y|y|N|n/
you probebly want to check if thats the only thing entred, 

$answer =~ m/^yn$/i  
 
^ begins with, $ ends with, i is for case insensetive.

Mark
 
- Original Message - 
From: "Paul Kraus" <[EMAIL PROTECTED]>
To: "'Vuctor Akinnagbe'" <[EMAIL PROTECTED]>; "Perl" <[EMAIL PROTECTED]>
Sent: Thursday, January 09, 2003 10:21 AM
Subject: RE: Delimiter Question


> I think you mean $answer m/[YyNn]/
> 
> yours is looking for $answer to contain "YyNn"
> the brackets mean any one of the following.
> 
> > -Original Message-
> > From: Vuctor Akinnagbe [mailto:[EMAIL PROTECTED]] 
> > Sent: Thursday, January 09, 2003 10:11 AM
> > To: [EMAIL PROTECTED]
> > Subject: Delimiter Question
> > 
> > 
> > How do I challenege more than one variable like I want to 
> > check for the input of Y N y or n for a yes no question. I 
> > put until $answer =~ m/YyNn/ that did not work. Anybody have 
> > any solutions?
> > 
> > 
> > -
> > Do you Yahoo!?
> > Yahoo! Mail Plus - Powerful. Affordable. Sign up now
> > 
> 
> 
> -- 
> To unsubscribe, e-mail: [EMAIL PROTECTED]
> For additional commands, e-mail: [EMAIL PROTECTED]
> 

-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]




RE: Best way to return largest of 3 Vars?

2003-01-10 Thread Bob Showalter
Tim Musson wrote:
> Hey all,
> 
>   I need to return the largest of 3 vars. Is there a better way than
>   nested IF statements? Maybe put them in an array and sort it?

You can write the sort without needing a separate array:

   $max = (sort {$b<=>$a} ($x, $y, $z))[0];

Or, you can do something like this

   $max = ($max = ($x > $y) ? $x : $y) > $z ? $max : $z;

(I'm sure somebody can simplify that)

If you get more than 3 vars, the sort is probably the cleanest way to write
it.

-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]




Re: Remove some, not all \n from a text block

2003-01-10 Thread R. Joseph Newton
Hi Alan,

Apparently, continue is not supported in Perl, but a conditional next seems to perform 
the same function.

Joseph

...perldoc -q continue turned up nothing.
...providing condition met, "next" makes it skip to the next iteration?


-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]




RE: Remove some, not all \n from a text block

2003-01-10 Thread Dan Muey
Not sure specifically about continue but just because perldoc doesn't turn up anything 
doesn't mean perl doesn't support it. It means that you either typed it wrong or your 
perl doc doesn't have that for some reason. Just fyi

-Original Message-
From: R. Joseph Newton [mailto:[EMAIL PROTECTED]] 
Sent: Friday, January 10, 2003 8:26 AM
To: Alan C.
Cc: [EMAIL PROTECTED]
Subject: Re: Remove some, not all \n from a text block


Hi Alan,

Apparently, continue is not supported in Perl, but a conditional next seems to perform 
the same function.

Joseph

...perldoc -q continue turned up nothing.
...providing condition met, "next" makes it skip to the next iteration?


-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]


--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]




RE: Perl Subroutines

2003-01-10 Thread Dan Muey
If you are on unix and index.cgi prints all of the html that you'd like in index.html 
then eithe command line or backtick in a script :

./index.cgi > index.html

Dan

-Original Message-
From: Bob X [mailto:[EMAIL PROTECTED]] 
Sent: Thursday, January 09, 2003 7:12 PM
To: [EMAIL PROTECTED]
Subject: Re: Perl Subroutines



"Joshua Scott" <[EMAIL PROTECTED]> wrote in message 
5D23931127B7EB409640001B7E8A6E32014A2AFA@PASNT32">news:5D23931127B7EB409640001B7E8A6E32014A2AFA@PASNT32...
> I've created a group of Perl subroutines to handle the creation and 
> layout of my web pages.  These subs are used when browsing to my 
> website. Basically all they do when invoked is print a bunch of HTML.  
> I've now run into the scenario where I'd like to use these same subs 
> to print static
web
> pages where the output doesn't go to the web browser, but instead goes 
> to
a
> file.  How could I go about doing that?
>
> Here's an example of what my subs look like:
>
> Sub opentbl {
> Print "";
> Print "";
> Print "";
> Print "";
> Print "";
> };
>
> I call the sub from webpages the standard way.
>
> I sure hope I explained this clearly.  I'm still getting used to Perl. 
> Thank you for any help you can provide!
>
> Joshua Scott
>
>
Not sure from the web but I do this:

sub web_file {
open(WEB_FILE, ">>filename.txt") || die "Unable to open $!";
print WEB_FILE "";
print WEB_FILE "";
print WEB_FILE "";
print WEB_FILE "";
print WEB_FILE "";
close( WEB_FILE);
}

You may be better served putting the text file in a variable like:

my $web_file = "path/to/file/filename.txt";

This is off the cuff. I know the sub works from the prompt since I use it onWindows to 
create batch files on the fly.

Hope this helps...or at least gives you an idea.

Bob



-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]


--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]




RE: bandwidth restricting

2003-01-10 Thread Dan Muey
If you really want to get into it you can parse the apache log and calculate bandwidth 
loosley o ntht althoug hh that won't include ftp, pop, smtp, etc.. Traffic. There's a 
module to help called Apache::ParseLog or something like that. 



-Original Message-
From: Victor Tsang [mailto:[EMAIL PROTECTED]] 
Sent: Thursday, January 09, 2003 9:03 PM
To: mod_perl
Cc: [EMAIL PROTECTED]
Subject: Re: bandwidth restricting


If you have a linux box, It might be a better idea to employ the traffic shapper that 
comes with the linux kernel instead.

Tor.

mod_perl wrote:
> 
> hi all,
>In my Lan I have a linux proxy .How  can i restrict the 
> bandwidth cosumed by each user using perl .Which module i can use .
>thanks in advance
> 
> shine
> 
> --
> To unsubscribe, e-mail: [EMAIL PROTECTED]
> For additional commands, e-mail: [EMAIL PROTECTED]

-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]


--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]




RE: Best way to return largest of 3 Vars?

2003-01-10 Thread Jenda Krynicky
From:   Bob Showalter <[EMAIL PROTECTED]>
> Tim Musson wrote:
> > Hey all,
> > 
> >   I need to return the largest of 3 vars. Is there a better way than
> >   nested IF statements? Maybe put them in an array and sort it?
> 
> You can write the sort without needing a separate array:
> 
>$max = (sort {$b<=>$a} ($x, $y, $z))[0];
> 
> Or, you can do something like this
> 
>$max = ($max = ($x > $y) ? $x : $y) > $z ? $max : $z;
> 
> (I'm sure somebody can simplify that)
> 
> If you get more than 3 vars, the sort is probably the cleanest way to
> write it.

Just for kicks I benchmarked a few solutions:

#!perl
use Benchmark;
use strict;
my $x = 4;
my $y = 2;
my $z = 45;

sub Bob2 {
my $max;
$max = ($max = ($x > $y) ? $x : $y) > $z ? $max : $z;
return $max;
}

sub Bob {
my $max = (sort {$b<=>$a} ($x, $y, $z))[0];
return $max;
}

sub GetLast {
my $max = (sort ($x, $y, $z))[-1];
return $max;
}

sub ListContext {
my ($max) = sort {$b<=>$a} ($x, $y, $z);
return $max;
}

sub For3If {
my $max = $x;$max = ($_ > $max ? $_ : $max) for ($x, $y, $z);
return $max;
}

sub ForModIf {
my $max = $x; for ($x, $y, $z) {$max = $_ if $_ > $max};
return $max;
}


timethese 100, {
Bob => \&Bob,
Bob2 => \&Bob2,
GetLast => \&GetLast,
ListContext => \&ListContext,
For3If => \&For3If,
ForModIf => \&ForModIf,
};
__END__

Benchmark: timing 100 iterations of Bob, Bob2, Bob2J, For3If, 
ForModIf, GetL
ast, ListContext...
   Bob:  3 wallclock secs ( 2.55 usr +  0.00 sys =  2.55 CPU) 
@ 391696.04/s (n=100)
  Bob2:  2 wallclock secs ( 1.51 usr +  0.00 sys =  1.51 CPU) 
@ 660938.53/s (n=100)
For3If:  6 wallclock secs ( 5.36 usr +  0.00 sys =  5.36 CPU) 
@ 186636.80/s (n=100)
  ForModIf:  4 wallclock secs ( 5.09 usr +  0.00 sys =  5.09 CPU) 
@ 196579.52/s (n=100)
   GetLast:  2 wallclock secs ( 2.75 usr +  0.00 sys =  2.75 CPU) 
@ 363108.21/s (n=100)
ListContext:  3 wallclock secs ( 2.31 usr +  0.00 sys =  2.31 CPU) 
@ 432338.95/s (n=100)
(Look at the CPU time, not the wallclock!)

Jenda
= [EMAIL PROTECTED] === http://Jenda.Krynicky.cz =
When it comes to wine, women and song, wizards are allowed 
to get drunk and croon as much as they like.
-- Terry Pratchett in Sourcery


-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]




RE: Perl Subroutines

2003-01-10 Thread Jenda Krynicky
From: "Scott, Joshua" <[EMAIL PROTECTED]>
> Let me add a little more info regarding my question.  The subroutines
> are already setup and can't be modified easily.  The basic task of all
> the different subs is to print to STDOUT.  I'd really like to be able
> to call this sub from another script and somehow redirect the output
> to a file without modifying the subs code.  

Most probably they do NOT write to STDOUT, but to the currently 
selected filehandle. That is they contain
print "Something\n";
and not
print STDOUT "Something\n";

In this case all you have to do is to select() a different 
filehandle.

open OUT, '> '.$filename or die "Can't open $filename : $!\n";
{
my $oldfh = select(OUT);
call_the_procedure(params);
select($oldfh);
}
close OUT;

See
perldoc -f select

If the functions really write to STDOUT you may either:

{
local *STDOUT; # the "redirection" is only local
open STDOUT, '> '.$filename or die "Can't open $filename : $!\n";
call_the_procedure(params);
close STDOUT;
}

or
{
local *OLDOUT; # to store the STDOUT
open OLDOUT, '>&STDOUT' or die "Can't dup the STDOUT : $!\n";
close STDOUT;
open STDOUT, '> '.$filename or die "Can't open $filename : $!\n";
call_the_procedure(params);
close STDOUT;
open STDOUT, '>&OLDOUT' or die "Can't restore the STDOUT : $!\n";
}

The second would be necessary if the procedure executes some external 
programs that need to be able to print to the same filehandle.

In either case make sure you restore the original STDOUT and/or 
selected flehandle.

HTH, Jenda
= [EMAIL PROTECTED] === http://Jenda.Krynicky.cz =
When it comes to wine, women and song, wizards are allowed 
to get drunk and croon as much as they like.
-- Terry Pratchett in Sourcery


-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]




Re: perl monger needed asap...

2003-01-10 Thread Jenda Krynicky
From:   Benjamin Jurado <[EMAIL PROTECTED]>
Subject:perl monger needed asap...

Please read "How To Ask Questions The Smart Way" 
(http://www.tuxedo.org/~esr/faqs/smart-questions.html#bespecific)
ASAP.

> how can i store the results in a array,hash,reference...
> 
> use File::Find;
> use strict;
> my $foo1="/path/to/something";
> sub foo{
> #some filtering operations or even passing to another object or
> #subroutine
> }
> find(\foo,$foo1);

find(\&foo,$foo1);

The very first example in the File::Find docs would have told you.
Run
perldoc File::Find

Jenda
= [EMAIL PROTECTED] === http://Jenda.Krynicky.cz =
When it comes to wine, women and song, wizards are allowed 
to get drunk and croon as much as they like.
-- Terry Pratchett in Sourcery


-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]




RE: Remove some, not all \n from a text block

2003-01-10 Thread Paul Johnson

Dan Muey said:

> -Original Message-
> From: R. Joseph Newton [mailto:[EMAIL PROTECTED]]
> Sent: Friday, January 10, 2003 8:26 AM
> To: Alan C.
> Cc: [EMAIL PROTECTED]
> Subject: Re: Remove some, not all \n from a text block
>
>
> Hi Alan,
>
> Apparently, continue is not supported in Perl, but a conditional next
> seems to perform the same function.
>
> Joseph
>
> ...perldoc -q continue turned up nothing.

perldoc -f continue

-- 
Paul Johnson - [EMAIL PROTECTED]
http://www.pjcj.net


-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]




RE: Remove some, not all \n from a text block

2003-01-10 Thread Dan Muey
Like I said, typed wrong. Didn't have time to go look for it but I thought it had to 
do with that -q.
Just to note I wasn't the one that said :

> Hi Alan,
>
> Apparently, continue is not supported in Perl, but a conditional next 
> seems to perform the same function.
>
> Joseph
>
:)

Dan

-Original Message-
From: Paul Johnson [mailto:[EMAIL PROTECTED]] 
Sent: Friday, January 10, 2003 9:33 AM
To: Dan Muey
Cc: R. Joseph Newton; Alan C.; [EMAIL PROTECTED]
Subject: RE: Remove some, not all \n from a text block



Dan Muey said:

> -Original Message-
> From: R. Joseph Newton [mailto:[EMAIL PROTECTED]]
> Sent: Friday, January 10, 2003 8:26 AM
> To: Alan C.
> Cc: [EMAIL PROTECTED]
> Subject: Re: Remove some, not all \n from a text block
>
>
> Hi Alan,
>
> Apparently, continue is not supported in Perl, but a conditional next 
> seems to perform the same function.
>
> Joseph
>
> ...perldoc -q continue turned up nothing.

perldoc -f continue

-- 
Paul Johnson - [EMAIL PROTECTED]
http://www.pjcj.net


--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]




Re: Best way to return largest of 3 Vars?

2003-01-10 Thread Tim Musson
Hey Jenda, 

My MUA believes you used Pegasus Mail for Windows (v4.02a)
to write the following on Friday, January 10, 2003 at 10:04:23 AM.

Thanks all! I know I can always count on this list!

Looks like we are going with this one.

JK> sub Bob {
JK> my $max = (sort {$b<=>$a} ($x, $y, $z))[0];
JK> return $max;
JK> }

-- 
Tim Musson
Flying with The Bat! eMail v1.62 Christmas Edition
Windows 2000 5.0.2195 (Service Pack 2)
Why is "abbreviated" such a long word?


-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]




Re: Best way to return largest of 3 Vars?

2003-01-10 Thread Jenda Krynicky
From: Tim Musson <[EMAIL PROTECTED]>
> Hey Jenda, 
> 
> My MUA believes you used Pegasus Mail for Windows (v4.02a)
> to write the following on Friday, January 10, 2003 at 10:04:23 AM.
> 
> Thanks all! I know I can always count on this list!

:-)
 
> Looks like we are going with this one.
> 
> JK> sub Bob {
> JK> my $max = (sort {$b<=>$a} ($x, $y, $z))[0];
> JK> return $max;
> JK> }

According to the benchmarks this one was slightly better 

my ($max) = sort {$b<=>$a} ($x, $y, $z);

Jenda
= [EMAIL PROTECTED] === http://Jenda.Krynicky.cz =
When it comes to wine, women and song, wizards are allowed 
to get drunk and croon as much as they like.
-- Terry Pratchett in Sourcery


-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]




Re: Best way to return largest of 3 Vars?

2003-01-10 Thread Tim Musson
Hey Jenda, 

My MUA believes you used Pegasus Mail for Windows (v4.02a)
to write the following on Friday, January 10, 2003 at 11:04:07 AM.

JK> According to the benchmarks this one was slightly better

JK> my ($max) = sort {$b<=>$a} ($x, $y, $z);

I thought "Bob2" was the better one...

$max = ($max = ($x > $y) ? $x : $y) > $z ? $max : $z;

,- [ from 3E1EEF07.25135.12C828A@localhost">mid:3E1EEF07.25135.12C828A@localhost ]
|Bob:  3 wallclock secs ( 2.55 usr +  0.00 sys =  2.55 CPU) 
| @ 391696.04/s (n=100)
|   Bob2:  2 wallclock secs ( 1.51 usr +  0.00 sys =  1.51 CPU) 
`-

We will still probably be using "Bob" as it seem easier to read.

btw, thanks for the benchmark test, I may try that on some other code
I have...

-- 
Tim Musson
Flying with The Bat! eMail v1.62 Christmas Edition
Windows 2000 5.0.2195 (Service Pack 2)
Don't meddle in the affairs of dragons./nYou're crunchy and taste good with ketchup.


-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]




RE: Best way to return largest of 3 Vars?

2003-01-10 Thread Jensen Kenneth B SrA AFPC/DPDMPQ
In the line
my $max = (sort {$b<=>$a} ($x, $y, $z))[0];

What is the "[0]" doing?

Also another question. While messing around with the compact version of if
statements I tried these.

$one = 1;
($one == 1) ? (print "\$one equals", print "$one") : (print "\$one does not
", print "equal 1");

Returns
1
$one equals 1

At first I thought the first "1" on a line by itself was a return flag or
something, until I did this

$one = 1;
($one == 1) ? ( print "$one", print "\$one equals") : (print "\$one does not
", print "equal 1");

Returns
$one equals 1
1

Then for a moment I just thought it was the order perl executes the
statements in the parens. But its printing "1" twice. "1" with the new line
by itself, then "1" at the end of the string where it is supposed to be...
But without a new line. If I change the conditional so that it is not true I
get some confusing results.

$one = 1;
($one == 2) ? ( print "$one", print "\$one equals") : (print "\$one does not
", print "equal 1");

Returns
Equal 1
$one does not 1

Reversed the order of the statements and this happens.

$one = 1;
($one == 2) ? ( print "$one", print "\$one equals") : (print "equal 1",
print "\$one does not ");

Returns
$one does not equal 1
1

I can live with reversing the order of statements when I want to do multiple
things in a short compact if. But why is it returning 1? Can it be
suppressed?

Ken

-Original Message-
From: Jenda Krynicky [mailto:[EMAIL PROTECTED]] 
Sent: Friday, January 10, 2003 10:04 AM
To: [EMAIL PROTECTED]
Subject: Re: Best way to return largest of 3 Vars?


From: Tim Musson <[EMAIL PROTECTED]>
> Hey Jenda, 
> 
> My MUA believes you used Pegasus Mail for Windows (v4.02a)
> to write the following on Friday, January 10, 2003 at 10:04:23 AM.
> 
> Thanks all! I know I can always count on this list!

:-)
 
> Looks like we are going with this one.
> 
> JK> sub Bob {
> JK> my $max = (sort {$b<=>$a} ($x, $y, $z))[0];
> JK> return $max;
> JK> }

According to the benchmarks this one was slightly better 

my ($max) = sort {$b<=>$a} ($x, $y, $z);

Jenda
= [EMAIL PROTECTED] === http://Jenda.Krynicky.cz =
When it comes to wine, women and song, wizards are allowed 
to get drunk and croon as much as they like.
-- Terry Pratchett in Sourcery


-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]



one liner replace / with \

2003-01-10 Thread Paul Kraus
I want to replace all forward slashes with back slashes is a file.
Using a one liner I tried

perl -I -i.bak -w -e 's!/!\\!g' map.bat

I get this error
useless use of a constant in void context at -e line 1.

this is on a windows xp machine.

Paul Kraus
Network Administrator
PEL Supply Company
216.267.5775 Voice
216-267-6176 Fax
www.pelsupply.com


-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]


RE: one liner replace / with \

2003-01-10 Thread Bob Showalter
Paul Kraus wrote:
> I want to replace all forward slashes with back slashes is a file.
> Using a one liner I tried 
> 
> perl -I -i.bak -w -e 's!/!\\!g' map.bat

1) You don't need -I

2) You do need -p

3) You probably need to use double-quotes instead of single, due to Windows
shell brain damage.

4) tr/// is an alternate to s///g you might consider:

   perl -pi.bak -e "tr./.\\." map.bat

> 
> I get this error
> useless use of a constant in void context at -e line 1.

I think this is because Windows is passing the single quotes along to Perl,
so it sees a single-quoted literal instead of a substitution operator.

> 
> this is on a windows xp machine.

-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]




RE: one liner replace / with \

2003-01-10 Thread Paul Kraus
that worked.

Now I wanted to replace any white space with a single space.

I used this command

perl -pi.bak -w -e "s/\s+/ /g" map.bat

That worked correctly but it removed all of my new lines.

Why should I use tr instead?

> -Original Message-
> From: Bob Showalter [mailto:[EMAIL PROTECTED]] 
> Sent: Friday, January 10, 2003 11:53 AM
> To: 'Paul Kraus'; Perl
> Subject: RE: one liner replace / with \
> 
> 
> Paul Kraus wrote:
> > I want to replace all forward slashes with back slashes is a file. 
> > Using a one liner I tried
> > 
> > perl -I -i.bak -w -e 's!/!\\!g' map.bat
> 
> 1) You don't need -I
> 
> 2) You do need -p
> 
> 3) You probably need to use double-quotes instead of single, 
> due to Windows shell brain damage.
> 
> 4) tr/// is an alternate to s///g you might consider:
> 
>perl -pi.bak -e "tr./.\\." map.bat
> 
> > 
> > I get this error
> > useless use of a constant in void context at -e line 1.
> 
> I think this is because Windows is passing the single quotes 
> along to Perl, so it sees a single-quoted literal instead of 
> a substitution operator.
> 
> > 
> > this is on a windows xp machine.
> 


-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]




Sybase DBlib & CGI issue

2003-01-10 Thread Andy Bridger
I have a perl cgi script that  needs to access a database using
Sybase::DBlib.

The CGI bit is working - am able to display text, forms etc correctly, but
when try to connect to the database it fails to connect.  Oddly the same db
connection script works in a different script - and the db connection even
works if run from the unix command line.

use Sybase::DBlib;

my $user = "xxxt";
my $pwd = "yyy";
my $server = "zzz";
my $dbh;

if ($dbh = new Sybase::DBlib $user, $pwd, $server) {
print "Server: $server \n";
$dbh->dbuse("kplus");
} else {
print  "Couldn't connect to $server ";
return -1;
}

This displays the server connection when run from the command line, but the
"Couldn't connect.." when run via the browser...

The web server is Apache running on Solaris if that makes any difference.

Any suggestions gratefully received.


> Andy Bridger
> 
> 
> 
> 

This email with all information contained herein or attached hereto may
contain confidential and/or privileged information intended for the
addressee(s) only.  If you have received this email in error, please contact
the sender and immediately delete this email in its entirety and any
attachments thereto.



-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]




RE: one liner replace / with \

2003-01-10 Thread Bob Showalter
Paul Kraus wrote:
> Now I wanted to replace any white space with a single space.
> 
> I used this command
> 
> perl -pi.bak -w -e "s/\s+/ /g" map.bat
> 
> That worked correctly but it removed all of my new lines.

Because new lines are whitespace. Adding -l (ell) to the perl command is the
easiest way to fix that:

   perl -lpi.bak -w -e "s/\s+/ /g" map.bat

-l basically chomp()'s each input line when it's read and then adds the \n
back on when it's printed back out. Handy!

> 
> Why should I use tr instead?

You shouldn't in this case.

-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]




menu

2003-01-10 Thread Dylan Boudreau
I am trying to make a small menu for a script and the options are 1 or 2
or 9.  I have it written like this
 
until ($selection == '1|2|9'){
 do some stuff
}
 
 
and it wont work.  I know it is something simple but I am a little
simple myself today and don't know what I am doing wrong.
 
 
Thanks,
 
Dylan



RE: menu

2003-01-10 Thread Wagner, David --- Senior Programmer Analyst --- WGO
Dylan Boudreau wrote:
> I am trying to make a small menu for a script and the options are 1
> or 2 or 9.  I have it written like this
> 
> until ($selection == '1|2|9'){
>  do some stuff
> }
> 
> 
> and it wont work.  I know it is something simple but I am a little
> simple myself today and don't know what I am doing wrong.
> 
> 
> Thanks,
> 
> Dylan

 until ( $selection =~ /^\s*[129]\s*$/ )

Wags ;)


**
This message contains information that is confidential
and proprietary to FedEx Freight or its affiliates.
It is intended only for the recipient named and for
the express purpose(s) described therein.
Any other use is prohibited.



-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]




RE: menu

2003-01-10 Thread Paul Kraus
this worked for me.


#!/usr/bin/perl -w
until ($selection=~/[129]/){
print "Hello\n";
$selection = 1;
}

I tried 1239.
129 print "hello" once.
3 is endless hello loop.

Or you can do
until (($selection==1)||($selection==2)||($selection==9)){
code;
}

hope that helps.

> -Original Message-
> From: Dylan Boudreau [mailto:[EMAIL PROTECTED]] 
> Sent: Friday, January 10, 2003 12:24 PM
> To: [EMAIL PROTECTED]
> Subject: menu
> 
> 
> I am trying to make a small menu for a script and the options 
> are 1 or 2 or 9.  I have it written like this
>  
> until ($selection == '1|2|9'){
>  do some stuff
> }
>  
>  
> and it wont work.  I know it is something simple but I am a 
> little simple myself today and don't know what I am doing wrong.
>  
>  
> Thanks,
>  
> Dylan
> 


-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]




RE: menu

2003-01-10 Thread Dan Muey
You need a regular expression like 
Until ($selection =~ m/^1$|^2$|^9$/) {
Do some stuff
}

The ^ and $ keep them from enterin say '12' or '109' or 'I love 1 monkey'.

Remove them if you only care that they at least type the digit and don't care if 
there's extra stuff

Dan

-Original Message-
From: Dylan Boudreau [mailto:[EMAIL PROTECTED]] 
Sent: Friday, January 10, 2003 11:24 AM
To: [EMAIL PROTECTED]
Subject: menu


I am trying to make a small menu for a script and the options are 1 or 2 or 9.  I have 
it written like this
 
until ($selection == '1|2|9'){
 do some stuff
}
 
 
and it wont work.  I know it is something simple but I am a little simple myself today 
and don't know what I am doing wrong.
 
 
Thanks,
 
Dylan

--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]




RE: Sybase DBlib & CGI issue

2003-01-10 Thread Dan Muey

Have it print $dbh->errstr to see what the database says is wrong.
At least that'd work with DBI not sure about Sybase::Dblib.

Regardless have it print the problem instead of just , 'sorry'

Not sure also but it sounds like apache may not have permission to access the database.

Ie you 'userbob' can access it but 'nobody' can't.

Dan
-Original Message-
From: Andy Bridger [mailto:[EMAIL PROTECTED]] 
Sent: Friday, January 10, 2003 11:03 AM
To: Beginners Perl (E-mail)
Subject: Sybase DBlib & CGI issue


I have a perl cgi script that  needs to access a database using Sybase::DBlib.

The CGI bit is working - am able to display text, forms etc correctly, but when try to 
connect to the database it fails to connect.  Oddly the same db connection script 
works in a different script - and the db connection even works if run from the unix 
command line.

use Sybase::DBlib;

my $user = "xxxt";
my $pwd = "yyy";
my $server = "zzz";
my $dbh;

if ($dbh = new Sybase::DBlib $user, $pwd, $server) {
print "Server: $server \n";
$dbh->dbuse("kplus");
} else {
print  "Couldn't connect to $server ";
return -1;
}

This displays the server connection when run from the command line, but the "Couldn't 
connect.." when run via the browser...

The web server is Apache running on Solaris if that makes any difference.

Any suggestions gratefully received.


> Andy Bridger
> 
> 
> 
> 

This email with all information contained herein or attached hereto may contain 
confidential and/or privileged information intended for the
addressee(s) only.  If you have received this email in error, please contact the 
sender and immediately delete this email in its entirety and any attachments thereto.



-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]


--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]




Re: Best way to return largest of 3 Vars?

2003-01-10 Thread Tim Musson
Hey Jensen, 

My MUA believes you used Internet Mail Service (5.5.2653.19)
to write the following on Friday, January 10, 2003 at 11:23:43 AM.

JKBSAD> my $max = (sort {$b<=>$a} ($x, $y, $z))[0];

JKBSAD> What is the "[0]" doing?

It is putting the largest value in $max. Try changing it to -1, it
will put the smallest in $max. Similar to how you access values in an
array.

-- 
Tim Musson
Flying with The Bat! eMail v1.62 Christmas Edition
Windows 2000 5.0.2195 (Service Pack 2)
Whoever has the most when he dies... IS DEAD!


-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]




Re: Best way to return largest of 3 Vars?

2003-01-10 Thread Tim Musson
Hey Jensen, 

My MUA believes you used Internet Mail Service (5.5.2653.19)
to write the following on Friday, January 10, 2003 at 11:23:43 AM.

JKBSAD> $one = 1;

JKBSAD> ($one == 1) ? (print "\$one equals", print "$one") : (print "\$one does not ", 
print "equal 1");

Why the double print statements?
,- [ you can change ]
| (print "\$one equals", print "$one")
`-
,- [ to ]
| (print "\$one equals $one")
`-

-- 
Tim Musson
Flying with The Bat! eMail v1.62 Christmas Edition
Windows 2000 5.0.2195 (Service Pack 2)
Hang up and drive. 


-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]




RE: Best way to return largest of 3 Vars?

2003-01-10 Thread Jensen Kenneth B SrA AFPC/DPDMPQ
The two print statements were there for the sake of having 2 commands. Most
of the time I have in statements I have more than one statement to execute
in the block.

(Condition) ? (if condition true statements) : (if condition false
statements);

Seems to me that multiple commands are executed in reverse order (right to
left).

-Original Message-
From: Tim Musson [mailto:[EMAIL PROTECTED]] 
Sent: Friday, January 10, 2003 11:47 AM
To: [EMAIL PROTECTED]
Subject: Re: Best way to return largest of 3 Vars?


Hey Jensen, 

My MUA believes you used Internet Mail Service (5.5.2653.19)
to write the following on Friday, January 10, 2003 at 11:23:43 AM.

JKBSAD> $one = 1;

JKBSAD> ($one == 1) ? (print "\$one equals", print "$one") : (print 
JKBSAD> "\$one does not ", print "equal 1");

Why the double print statements?
,- [ you can change ]
| (print "\$one equals", print "$one")
`-
,- [ to ]
| (print "\$one equals $one")
`-

-- 
Tim Musson
Flying with The Bat! eMail v1.62 Christmas Edition
Windows 2000 5.0.2195 (Service Pack 2)
Hang up and drive. 


-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]



RE: menu

2003-01-10 Thread Dylan Boudreau
Thanks everyone, for some reason a regexpr never came to mind. 

Good thing its Friday,

Dylan

-Original Message-
From: Dan Muey [mailto:[EMAIL PROTECTED]] 
Sent: January 10, 2003 1:35 PM
To: Dylan Boudreau; [EMAIL PROTECTED]
Subject: RE: menu


You need a regular expression like 
Until ($selection =~ m/^1$|^2$|^9$/) {
Do some stuff
}

The ^ and $ keep them from enterin say '12' or '109' or 'I love 1
monkey'.

Remove them if you only care that they at least type the digit and don't
care if there's extra stuff

Dan

-Original Message-
From: Dylan Boudreau [mailto:[EMAIL PROTECTED]] 
Sent: Friday, January 10, 2003 11:24 AM
To: [EMAIL PROTECTED]
Subject: menu


I am trying to make a small menu for a script and the options are 1 or 2
or 9.  I have it written like this
 
until ($selection == '1|2|9'){
 do some stuff
}
 
 
and it wont work.  I know it is something simple but I am a little
simple myself today and don't know what I am doing wrong.
 
 
Thanks,
 
Dylan

-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]





-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]




Re: Best way to return largest of 3 Vars?

2003-01-10 Thread Paul Johnson
On Fri, Jan 10, 2003 at 11:53:15AM -0600, Jensen Kenneth B SrA AFPC/DPDMPQ wrote:
> From: Tim Musson [mailto:[EMAIL PROTECTED]] 
> > 
> > JKBSAD> $one = 1;
> > 
> > JKBSAD> ($one == 1) ? (print "\$one equals", print "$one") : (print 
> > JKBSAD> "\$one does not ", print "equal 1");
> > 
> > Why the double print statements?
> 
> The two print statements were there for the sake of having 2 commands.

print "\$one equals", print "$one"

is just one statement.  It is a print statement which prints a list.
The first element in the list is the string "\$one equals".  The second
element is the result of the expression C.  To determine
the result of that expression it is executed, with the side effect of
printing "$one".  The return value is true (1 in this case) if the print
succeeded.

So the final list printed is ("\$one equals", 1).

> Seems to me that multiple commands are executed in reverse order (right to
> left).

No.  Statements are always executed in the order they are encountered.
If that does not suit you, check out Befunge and other similar
languages ;-)

-- 
Paul Johnson - [EMAIL PROTECTED]
http://www.pjcj.net

-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]




Re: checking if a file is empty

2003-01-10 Thread John W. Krahn
Pradeep Goel wrote:
> 
> Hi all

Hello,

> ///
> if($TYPE eq "HP-UX")
>   {  `/usr/sbin/swlist | grep  "OV NNM" |cut -f1> RF1 `;}
> else
>   {  `find /system/ -name deins_patch |cut -f3 -d /  > RF1`; }
> 
> #
> how to check if the  newly made file RF1 is empty or not ?
> #
> open(RFh1,"RF1") or die "Not able to open RF1 \ n";
>   my @pachs =  ;
> my($num3)  = $pachs[0]=~ /_(\d+)$/;
> 
> I want $num3 to be 0 if   RF1  is empty .

Why not just store the contents from the backticks?

my $num3;
if ( $TYPE eq 'HP-UX' ) {
($num3) = map /^_(\d+)\t.*OV NNM/, `/usr/sbin/swlist`;
}
else {
($num3) = map m!/[^/]*/_(\d+)!, `find /system/ -name deins_patch`
}




John
-- 
use Perl;
program
fulfillment

-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]




Re: Top Posting Preferences (was navigate the directories)

2003-01-10 Thread Kegs
On Fri, 2003-01-10 at 01:23, R. Joseph Newton wrote:
> Hi James,
> 
> You had one good point there.  I have now turned "automatically quote reply" 
> off in my m,ailer preferences.  Now my replies should include only such part
> of the originals as is necessary to make the connection to the prior post.

Well that is some improvement anyway ;)
  
> I will answer another point, also:
> 
> "...every paragraph appeared on a different line."
> 
> Of course--which is the only place for a line break in the current century.
> I am not taking responsibility for someone elses choice to read their mail 
> in a dripping cave by the light of a tallow candle.

Then could you please set your line wrap to something civilised, 72
characters for preference. I'm not using anything particularly
old-school, just Ximian Evolution.

-- 
James
[EMAIL PROTECTED]   invert to reply

Linux- 'Cos Micro$oft is for Capitalists running DOS


-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]




Re: Remove some, not all \n from a text block

2003-01-10 Thread John W. Krahn
"Alan C." wrote:
> 
> John W. Krahn wrote:
> > "Alan C." wrote:
> 
> > Here is one way to do it:
> >
> > #!/perl/bin/perl -w
> > use strict;
> >
> > my $text = do { local $/; <> };
> > $text =~ s/\n(?!\.|\z)/ /g;
> > print $text;
> >
> Your code does the job just super! Thanks!
> The (|) parenthesis "group" with left side | right side sandwiched
> between the parenthesis
> The | means "or" right?

That is correct.

> then \z means end of string (end of my entire small amount of text)
> According to MRE2, the ?! is a fail-look ahead position matcher of sorts
> that enables a match-fail combo characteristic so all possible matches
> are returned?

The (?!) is a zero-width (doesn't advance the search position) negative
look-ahead assertion.  The substitution (s///) replaces all (/g global
option) newlines with a space but only if the newline is NOT followed by
a dot (.) or NOT at the end of the string (\z).



John
-- 
use Perl;
program
fulfillment

-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]




Re: Delimiter Question

2003-01-10 Thread John W. Krahn
Mark Goland wrote:
> 
> > How do I challenege more than one variable like I want to
> >  check for the input of Y N y or n for a yes no question. I
> >  put until $answer =~ m/YyNn/ that did not work. Anybody have
> > any solutions?
> 
> the way you did it, would need to use or operator
> $answer =~ m/Y|y|N|n/
> you probebly want to check if thats the only thing entred,
> 
> $answer =~ m/^yn$/i
> 
> ^ begins with, $ ends with, i is for case insensetive.

That would work if the user entered the string "yn" (or "YN" or "Yn" or
"yN".)  It should be either:

$answer =~ m/^(?:y|n)$/i;

Or:

$answer =~ m/^(?i:y|n)$/;

Or:

$answer =~ m/^[yn]$/i;


John
-- 
use Perl;
program
fulfillment

-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]




Re: Why can't use SQL "GROUP BY..."?

2003-01-10 Thread Philip Newton
On Thu, 9 Jan 2003 22:59:03 +0800 (CST), [EMAIL PROTECTED] (Gary fung)
wrote:

> My coding is similar as:
> 
>  $value2 = $dbh->prepare("SELECT page FROM $Table 
> 
> GROUP BY page") || die "Couldn't add record, ".$dbh->errstr();
> 
> Whenever I use "GROUP BY.." , an error statement will go out :
> 
> "SQL ERROR: Can't find table names in FROM clause!"

Others have pointed out the possibility that $Table may be empty. I'd
like to add that I think there's another error -- as far as I know,
GROUP BY can only be used when you have aggregate functions such as SUM,
MAX, COUNT(...) etc. (For example, "SELECT custno, count(ordernum) FROM
orders GROUP BY custno ORDER BY 2 DESC" to select the customers together
with the number of orders, grouped by customer but sorted by number of
orders.)

Did you mean ORDER BY, perhaps?

Cheers,
Philip

--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]




RE: Why can't use SQL "GROUP BY..."?

2003-01-10 Thread Dan Muey
I apologize if this has already been covered to but...

Can you run that command by hand  and does it work?
Do this to see is both $Table has a value and if the generated code is actaully a 
valid sql command.


$query = "SELECT page FROM $Table GROUP BY page";
print " QUERY -$query-  \n"
$value2 = $dbh->prepare($query) || die "Couldn't add record, ".$dbh->errstr();

Then paste the query into your program and see if it takes it.
IE
Mysql> SELECT page FROM monkey GROUP BY page;

You could also you use DBI->trace.

Again if this has already been covered sorry, I've been away.

Dan

-Original Message-
From: Philip Newton [mailto:[EMAIL PROTECTED]] 
Sent: Thursday, January 09, 2003 11:34 PM
To: Gary fung
Cc: [EMAIL PROTECTED]; [EMAIL PROTECTED]
Subject: Re: Why can't use SQL "GROUP BY..."?


On Thu, 9 Jan 2003 22:59:03 +0800 (CST), [EMAIL PROTECTED] (Gary fung)
wrote:

> My coding is similar as:
> 
>  $value2 = $dbh->prepare("SELECT page FROM $Table
> 
> GROUP BY page") || die "Couldn't add record, ".$dbh->errstr();
> 
> Whenever I use "GROUP BY.." , an error statement will go out :
> 
> "SQL ERROR: Can't find table names in FROM clause!"

Others have pointed out the possibility that $Table may be empty. I'd like to add that 
I think there's another error -- as far as I know, GROUP BY can only be used when you 
have aggregate functions such as SUM, MAX, COUNT(...) etc. (For example, "SELECT 
custno, count(ordernum) FROM orders GROUP BY custno ORDER BY 2 DESC" to select the 
customers together with the number of orders, grouped by customer but sorted by number 
of
orders.)

Did you mean ORDER BY, perhaps?

Cheers,
Philip

-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]


--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]




sorting hash after deref

2003-01-10 Thread Yacketta, Ronald
Folks,
(B
(BCan some one kindly slap me silly and show me where I went south?
(B
(B
(Bsub dbMonthlySelect() {
(Bmy $query;
(Bmy $result;
(B
(B$query = "select * from mbstats_se where
(BSTATDATE=TO_DATE('12/30/02','MM/DD/YY')";
(B$result = &doQuery($query,'dbMonthlySelect');
(B
(Bmy %hash = %{$result->fetchrow_hashref};
(B
(Bforeach my $i ( sort { $a <=> $b } (keys (%hash))) {
(B   print "$i => $hash{$i}\n" if ( defined $hash{$i} );
(B }
(B}
(B
(BI want to sort the hash and print out only the defined key $B"N(J value pairs
(B
(B-Ron
(B
(B-- 
(BTo unsubscribe, e-mail: [EMAIL PROTECTED]
(BFor additional commands, e-mail: [EMAIL PROTECTED]



Re: Remove some, not all \n from a text block

2003-01-10 Thread Paul Johnson
On Fri, Jan 10, 2003 at 09:34:18AM -0600, Dan Muey wrote:

> Just to note I wasn't the one that said :
> 
> > Hi Alan,
> >
> > Apparently, continue is not supported in Perl, but a conditional next 
> > seems to perform the same function.
> >
> > Joseph
> >
> :)

No.  But unfortunately your mailer doesn't make it very easy to keep the
attibutions sensible.  It also sent long lines, broke the threading, and
encouraged you to top-post, and you were unable to resist the tempation.

Oh, hold on.  Am I in the wrong thread?

;-)

> -Original Message-
> From: Paul Johnson [mailto:[EMAIL PROTECTED]] 
> Sent: Friday, January 10, 2003 9:33 AM
> To: Dan Muey
> Cc: R. Joseph Newton; Alan C.; [EMAIL PROTECTED]
> Subject: RE: Remove some, not all \n from a text block
> 
> 
> 
> Dan Muey said:
> 
> > -Original Message-
> > From: R. Joseph Newton [mailto:[EMAIL PROTECTED]]
> > Sent: Friday, January 10, 2003 8:26 AM
> > To: Alan C.
> > Cc: [EMAIL PROTECTED]
> > Subject: Re: Remove some, not all \n from a text block
> >
> >
> > Hi Alan,
> >
> > Apparently, continue is not supported in Perl, but a conditional next 
> > seems to perform the same function.
> >
> > Joseph
> >
> > ...perldoc -q continue turned up nothing.
> 
> perldoc -f continue

-- 
Paul Johnson - [EMAIL PROTECTED]
http://www.pjcj.net

-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]




Formfeed in html (perl/cgi)

2003-01-10 Thread dhoubrechts
Can I put a formfeed in a perl cgi ?
I've tried print "\f" or something like but I can't force a new page.
Can someone help me ?

-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]




Formfeed in html (perl/cgi)

2003-01-10 Thread dhoubrechts
Can I put a formfeed in a perl cgi ?
I've tried print "\f" or something like but I can't force a new page.
Can someone help me ?

-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]




RE: Formfeed in html (perl/cgi)

2003-01-10 Thread Bob Showalter
dhoubrechts wrote:
> Can I put a formfeed in a perl cgi ?
> I've tried print "\f" or something like but I can't force a new page.
> Can someone help me ?

This is not a Perl issue. See:



-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]




Epoch midnight

2003-01-10 Thread Scott, Deborah
I thought I understood the answer, but I need more details.

What exactly would I enter if I want a program to find the epoch time for
midnight each night? I know how to find "current" time and date in both
"human" time and epoch time.

I want to generate a report that displays the events that are scheduled to
occur each day. (from midnight to midnight)

Thanks!

Scotty


-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]




RE: Epoch midnight

2003-01-10 Thread Mark Anderson

> What exactly would I enter if I want a program to find the epoch time for
> midnight each night? I know how to find "current" time and date in both
> "human" time and epoch time.

I can't give you code, because I haven't worked with perl's various time 
functions, but logically, I would get the epoch time for 'now', and mod 
it by the number of ticks in a given day.  I would then subtract the result
from the 'now' variable, and that should give me midnight this morning.  I
would write a perl script that only did this, and then converted the result
to a readable time/date format to double check my math before copying the
code into my real script.

Hope this helps,
/\/\ark

-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]




CGI sessions and Client's OS

2003-01-10 Thread aman raheja
Hello
I am using Perl/CGI on Linux (with Apache).
Some users have cookies disabled in their browsers and some are using the
old ones, which cause problems, along with Netscape.
Anyhow, I am looking for following solutions
1. How do we know the Operating System of the Client's system?
2. Where can I find some good documentation on Session implementation using
CGI?

Thank you
Aman

-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]




Re: Remove some, not all \n from a text block

2003-01-10 Thread R. Joseph Newton
"perldoc -f continue"
   Paul Johnson - [EMAIL PROTECTED]

Hmm, okay, it's there, I see.  I'm not sure I would be in a hurry to use it, though.  
I think a well-construction flow within a block should obviate any need for it.  The 
next statement, though, is very useful, and I think that was the usage he was looking 
for.

Joseph


-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]




hash sorting

2003-01-10 Thread Yacketta, Ronald
Can some please help here :)

I have the following


sub dbMonthlySelect() {
my $query;
my $result;

$query = "select * from mbstats_se where 
STATDATE=TO_DATE('12/30/02','MM/DD/YY')";
$result = &doQuery($query,'dbMonthlySelect');

my $i = $result->fetchrow_hashref;
for my $key (sort { $i->{$b} <=> $i->{$a} } (keys %$i)) {
print "$key = $i->{$key} \n" if defined $i->{$key};
}

}

and it sorts like this:


I1 = 541
I2 = 160
I4 = 40
I3 = 32
STATDATE = 30-DEC-02
I5 = 9
I6 = 8
I8 = 6
I11 = 5
I7 = 4
I18 = 4
I14 = 3
I15 = 3
I17 = 3
I13 = 3
I21 = 2
I10 = 2
I98 = 1
I20 = 1
I16 = 1
I23 = 1
SYSTEM = wb0300ux124
DATATYPE = OrderSubmit




When it should be like this:
 I
DATATYPE = OrderSubmit
STATDATE = 30-DEC-02
SYSTEM = wb0300ux124
I1 = 541
I2 = 160
I3 = 32
I4 = 40
I5 = 9
I6 = 8
I7 = 4
I8 = 6
I10 = 2
I11 = 5
I13 = 3
I14 = 3
I15 = 3
I16 = 1
I17 = 3
I18 = 4
I21 = 2
I20 = 1
I23 = 1
I98 = 1

-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]




RE: hash sorting

2003-01-10 Thread Timothy Johnson

Try using 'cmp' instead of '<=>' in your sort.  Then it will sort
alphanumerically.

-Original Message-
From: Yacketta, Ronald [mailto:[EMAIL PROTECTED]]
Sent: Friday, January 10, 2003 4:43 PM
To: [EMAIL PROTECTED]
Subject: hash sorting


Can some please help here :)

I have the following


sub dbMonthlySelect() {
my $query;
my $result;

$query = "select * from mbstats_se where
STATDATE=TO_DATE('12/30/02','MM/DD/YY')";
$result = &doQuery($query,'dbMonthlySelect');

my $i = $result->fetchrow_hashref;
for my $key (sort { $i->{$b} <=> $i->{$a} } (keys %$i)) {
print "$key = $i->{$key} \n" if defined $i->{$key};
}

}

and it sorts like this:


I1 = 541
I2 = 160
I4 = 40
I3 = 32
STATDATE = 30-DEC-02
I5 = 9
I6 = 8
I8 = 6
I11 = 5
I7 = 4
I18 = 4
I14 = 3
I15 = 3
I17 = 3
I13 = 3
I21 = 2
I10 = 2
I98 = 1
I20 = 1
I16 = 1
I23 = 1
SYSTEM = wb0300ux124
DATATYPE = OrderSubmit




When it should be like this:
 I
DATATYPE = OrderSubmit
STATDATE = 30-DEC-02
SYSTEM = wb0300ux124
I1 = 541
I2 = 160
I3 = 32
I4 = 40
I5 = 9
I6 = 8
I7 = 4
I8 = 6
I10 = 2
I11 = 5
I13 = 3
I14 = 3
I15 = 3
I16 = 1
I17 = 3
I18 = 4
I21 = 2
I20 = 1
I23 = 1
I98 = 1

-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]




Re: hash sorting

2003-01-10 Thread Wiggins d'Anconia


Timothy Johnson wrote:

Try using 'cmp' instead of '<=>' in your sort.  Then it will sort
alphanumerically.


This does not appear to help, perldoc perlop says:

"Binary "cmp" returns -1, 0, or 1 depending on whether the left argument
is stringwise less than, equal to, or greater than the right argument."

Which the 30-Dec-02 is still in the same order stringwise.  Depending on 
your database you may be able to fix this by specifying your query as 
STARTDATE, SYSTEM, TYPE, *, and then not including the first 3 elements 
in the print, or you could skip any non /I\d+/ keys in the hash and then 
print them at the bottom.  There should be a way to get sort to do it 
correctly but this escapes me at the moment...

http://danconia.org

-Original Message-
From: Yacketta, Ronald [mailto:[EMAIL PROTECTED]]
Sent: Friday, January 10, 2003 4:43 PM
To: [EMAIL PROTECTED]
Subject: hash sorting


Can some please help here :)

I have the following


sub dbMonthlySelect() {
my $query;
my $result;

$query = "select * from mbstats_se where
STATDATE=TO_DATE('12/30/02','MM/DD/YY')";
$result = &doQuery($query,'dbMonthlySelect');

my $i = $result->fetchrow_hashref;
for my $key (sort { $i->{$b} <=> $i->{$a} } (keys %$i)) {
print "$key = $i->{$key} \n" if defined $i->{$key};
}

}

and it sorts like this:


I1 = 541
I2 = 160
I4 = 40
I3 = 32
STATDATE = 30-DEC-02
I5 = 9
I6 = 8
I8 = 6
I11 = 5
I7 = 4
I18 = 4
I14 = 3
I15 = 3
I17 = 3
I13 = 3
I21 = 2
I10 = 2
I98 = 1
I20 = 1
I16 = 1
I23 = 1
SYSTEM = wb0300ux124
DATATYPE = OrderSubmit




When it should be like this:
 I
DATATYPE = OrderSubmit
STATDATE = 30-DEC-02
SYSTEM = wb0300ux124
I1 = 541
I2 = 160
I3 = 32
I4 = 40
I5 = 9
I6 = 8
I7 = 4
I8 = 6
I10 = 2
I11 = 5
I13 = 3
I14 = 3
I15 = 3
I16 = 1
I17 = 3
I18 = 4
I21 = 2
I20 = 1
I23 = 1
I98 = 1




--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]




Re: hash sorting

2003-01-10 Thread david
Ronald Yacketta wrote:

> Can some please help here :)
> 
> I have the following
> 
> 
> sub dbMonthlySelect() {
> my $query;
> my $result;
> 
> $query = "select * from mbstats_se where
> STATDATE=TO_DATE('12/30/02','MM/DD/YY')"; $result =
> &doQuery($query,'dbMonthlySelect');
> 
> my $i = $result->fetchrow_hashref;
> for my $key (sort { $i->{$b} <=> $i->{$a} } (keys %$i)) {
> print "$key = $i->{$key} \n" if defined
> $i->{$key};
> }
> 
> }
> 

i don't know what particular order you want but have you try:

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

my @array = qw(
I1=541
I2=160
I4=40
I3=32
STATDATE=30-DEC-02
I14=3
I15=3
SYSTEM=wb0300ux124
DATATYPE=OrderSubmit);

print "$_\n" for(sort {
my ($f1) = $a =~ /^I(\d+)/;
my ($f2) = $b =~ /^I(\d+)/;

   return $f1 <=> $f2 if($f1  && $f2);
   return 1   if($f1  && !$f2);
   return -1  if(!$f1 && $f2);
   return $a cmp $b;

} @array);

__END__

prints:

DATATYPE=OrderSubmit
STATDATE=30-DEC-02
SYSTEM=wb0300ux124
I1=541
I2=160
I3=32
I4=40
I14=3
I15=3

know what the above does because depends on your data, it might not work. it 
should give you a place to start.

david

-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]




Re: Delimiter Question

2003-01-10 Thread Mark Goland
Whoops.
$answer =~ m/^y|n$/i

:O)

- Original Message - 
From: "John W. Krahn" <[EMAIL PROTECTED]>
To: <[EMAIL PROTECTED]>
Sent: Friday, January 10, 2003 2:38 PM
Subject: Re: Delimiter Question


> Mark Goland wrote:
> > 
> > > How do I challenege more than one variable like I want to
> > >  check for the input of Y N y or n for a yes no question. I
> > >  put until $answer =~ m/YyNn/ that did not work. Anybody have
> > > any solutions?
> > 
> > the way you did it, would need to use or operator
> > $answer =~ m/Y|y|N|n/
> > you probebly want to check if thats the only thing entred,
> > 
> > $answer =~ m/^yn$/i
> > 
> > ^ begins with, $ ends with, i is for case insensetive.
> 
> That would work if the user entered the string "yn" (or "YN" or "Yn" or
> "yN".)  It should be either:
> 
> $answer =~ m/^(?:y|n)$/i;
> 
> Or:
> 
> $answer =~ m/^(?i:y|n)$/;
> 
> Or:
> 
> $answer =~ m/^[yn]$/i;
> 
> 
> John
> -- 
> use Perl;
> program
> fulfillment
> 
> -- 
> To unsubscribe, e-mail: [EMAIL PROTECTED]
> For additional commands, e-mail: [EMAIL PROTECTED]
> 

-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]




RE: hash sorting

2003-01-10 Thread Timothy Johnson

Yup.  I guess I shouldn't answer questions on the last hour of a busy work
week, but I'll give it another shot.  I suppose you could try something
along these lines:

foreach(sort keys %$i){
  push(@sorted,$_) unless /^I\d+$/;
}
foreach(sort keys %$i){
  push(@sorted,$_) if /^I\d+$/;
}

now @sorted should have your keys sorted stringwise with the 'I' keys at the
end.  I don't know if that's what you want, but it's an idea.

-Original Message-
From: Wiggins d'Anconia [mailto:[EMAIL PROTECTED]]
Sent: Friday, January 10, 2003 5:06 PM
To: 'Yacketta, Ronald'
Cc: [EMAIL PROTECTED]
Subject: Re: hash sorting




Timothy Johnson wrote:
> Try using 'cmp' instead of '<=>' in your sort.  Then it will sort
> alphanumerically.
> 
This does not appear to help, perldoc perlop says:

"Binary "cmp" returns -1, 0, or 1 depending on whether the left argument
is stringwise less than, equal to, or greater than the right argument."

Which the 30-Dec-02 is still in the same order stringwise.  Depending on 
your database you may be able to fix this by specifying your query as 
STARTDATE, SYSTEM, TYPE, *, and then not including the first 3 elements 
in the print, or you could skip any non /I\d+/ keys in the hash and then 
print them at the bottom.  There should be a way to get sort to do it 
correctly but this escapes me at the moment...

-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]




Re: sorting hash after deref

2003-01-10 Thread Mark Goland

(B> foreach my $i ( sort { $a <=> $b } (keys (%hash))) {
(B>print "$i => $hash{$i}\n" if ( defined $hash{$i} );
(B>  }
(B> }
(B>
(B
(Bhow about 
(B
(B  foreach my $i ( sort (   keys(%hash)   ) ) {
(Bprint "$i => $hash{$i}\n" if ( defined $hash{$i} );
(B  }
(B
(B
(B
(B- Original Message -
(BFrom: "Yacketta, Ronald" <[EMAIL PROTECTED]>
(BTo: <[EMAIL PROTECTED]>
(BSent: Friday, January 10, 2003 4:11 PM
(BSubject: sorting hash after deref
(B
(B
(B> Folks,
(B>
(B> Can some one kindly slap me silly and show me where I went south?
(B>
(B>
(B> sub dbMonthlySelect() {
(B> my $query;
(B> my $result;
(B>
(B> $query = "select * from mbstats_se where
(B> STATDATE=TO_DATE('12/30/02','MM/DD/YY')";
(B> $result = &doQuery($query,'dbMonthlySelect');
(B>
(B> my %hash = %{$result->fetchrow_hashref};
(B>
(B> foreach my $i ( sort { $a <=> $b } (keys (%hash))) {
(B>print "$i => $hash{$i}\n" if ( defined $hash{$i} );
(B>  }
(B> }
(B>
(B> I want to sort the hash and print out only the defined key $B"N(B value pairs
(B>
(B> -Ron
(B>
(B> --
(B> To unsubscribe, e-mail: [EMAIL PROTECTED]
(B> For additional commands, e-mail: [EMAIL PROTECTED]
(B>
(B
(B
(B-- 
(BTo unsubscribe, e-mail: [EMAIL PROTECTED]
(BFor additional commands, e-mail: [EMAIL PROTECTED]



Re: Epoch midnight

2003-01-10 Thread Todd W


Deborah Scott wrote:

I thought I understood the answer, but I need more details.

What exactly would I enter if I want a program to find the epoch time for
midnight each night? I know how to find "current" time and date in both
"human" time and epoch time.

I want to generate a report that displays the events that are scheduled to
occur each day. (from midnight to midnight)



[trwww@devel_rh trwww]$ perl
use Time::Local;
($day, $month, $year) = ( localtime() )[3 .. 5];

$epoch = timelocal( 0, 0, 0, $day, $month, $year );

print( scalar( localtime( $epoch ) ), "\n" );
Ctrl-D
Fri Jan 10 00:00:00 2003

$epoch holds the seconds between the epoch and today at midight.

Todd W.





--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]




build an array from a pattern match?

2003-01-10 Thread David Nicely
Hello,

I am a total beginner, so any help or a pointer to an appropriate doc will be 
appreciated.


I am trying to read a file, and find all the lines that look like;
"Finding 111" where "111" could be any number with any amount of digits.

What I am trying to do now is to assign a variable to that number for later use. or 
even better; gather all the numbers (from those specific lines only) and put them into 
an array.


use File::Slurp;
my @log = read_file($logfile);

my $lines;  
foreach $lines (@log) {($lines =~ /Finding (.*)/)}; 


-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]




Re: Delimiter Question

2003-01-10 Thread John W. Krahn
Mark Goland wrote:
> 
> From: "John W. Krahn" <[EMAIL PROTECTED]>
> 
> > Mark Goland wrote:
> > >
> > > the way you did it, would need to use or operator
> > > $answer =~ m/Y|y|N|n/
> > > you probebly want to check if thats the only thing entred,
> > >
> > > $answer =~ m/^yn$/i
> > >
> > > ^ begins with, $ ends with, i is for case insensetive.
> >
> > That would work if the user entered the string "yn" (or "YN" or "Yn" or
> > "yN".)  It should be either:
> >
> > $answer =~ m/^(?:y|n)$/i;
> >
> > Or:
> >
> > $answer =~ m/^(?i:y|n)$/;
> >
> > Or:
> >
> > $answer =~ m/^[yn]$/i;
> 
> Whoops.
> $answer =~ m/^y|n$/i

That means $answer starts with 'y' or ends with 'n'.


John
-- 
use Perl;
program
fulfillment

-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]




possible improvement(s)

2003-01-10 Thread Yacketta, Ronald
Hello All,

I am sure someone out their in Perl land can offer a better solution
to the following.

###
### slurp in all the required data for the report
###
open ($LOG,"cat $g_logdir/OrderServer-*.log|")
or die ( "Unable to open $g_logdir/OrderServer-*.log :
$!");


as well as this

###
### Capture specific errors
###
if( $_ =~ /^<$g_date.*Throw|Orphan/ && $_ !~ /Throwing/) {
$err2033++ if ( $_ =~ /error 2033/);# MQGET error's
$errEMPL++ if ( $_ =~ /Number: 6048/);  # EMPL NOT ON 
SALES/REP TABLE
$errMASTER++ if ( $_ =~ /Number: 50/);  # MASTER ORDER NUMBER 
ALREADY IN USE
$tmp++; # All errors
# Capture the error message for DB insertion later
push( @errors, $1) if ( $_ =~ /^<$g_date.*Reason: (.*)/);
}

###
### Count number of successful order submits
###
if ( $_ =~ /^<$g_date.*Units <(.*)> Submitted successfully/) {
$Units{$1}++;
$success++;
$totalUnits += $1;
$above4++ if ( $1 > 4 );
}

-- 
Regards,
 Ronald  mailto:[EMAIL PROTECTED]

-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]