Re: help with compiling on win2000 with vs.net

2004-07-02 Thread Randy W. Sims
lonnie percent wrote:
INCLUDE=C:\Program Files\Microsoft Visual Studio .NET
2003\SDK\v1.1\include\;C:\Program Files\Microsoft Visual Studio
.NET\Frame

LIB=C:\Program Files\Microsoft Visual Studio .NET
2003\SDK\v1.1\Lib\;C:\Program Files\Microsoft Visual Studio .NET\Fra
meworkSDK\

*Path is cut off in set. this is path from echo %PATH%
C:\PROGRA~1\MICROS~3.NET\Vc7\include
This should not be in PATH; it should be in INCLUDE. It's unclear why 
the vcvars batch file did not set this up correctly. I still use MSVS6, 
so maybe something changed? You might want to check the help files for 
all the batch files in the MSVS directory.

Randy.
--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
http://learn.perl.org/ http://learn.perl.org/first-response



Re: Broken links

2004-07-02 Thread Randy W. Sims
Brian Volk wrote:
Hi All,
I'm still very much learning and need a little help getting started w/ my
next project... :-)
I manage a web site that has links to other web sites (MSDS - material
safety data sheets).  When the web sites that I'm linking to change their
pages, my links break.  I need to create a program that will check to see if
I have any broken links
The web site was written in JavaScript.  The files that contain the URL for
the MSDS links are just notepad .txt files.  These files also contain the
short description to the product; for example:
J:\flash_host\ecomm\descriptions\product\small\70005.txt
contains.
Non-acid disinfectant bathroom cleaner. Ready-to-use. Kills HBV and HCV on
inanimate surfaces. EPA Reg. #5741-18  ~
http://www.spartanchemical.com/sfa/MSDSRep.nsf/99b229d7d7868537852567e0006d7
a64/671a7d07c725353885256e9f0063c4cc!OpenDocument  

So I guess I need to create a program that will check each file in the
J:\flash_host\ecomm\descriptions\product\small directory and search for the
http://www string (?) then (ping ?) that URL?  The next step would be to
return the file name (70005.txt) of the broken links to a file??Does
this sound like I'm on the right track..?  I have my trusty Learning Perl
book, so I'm not totally lost. 
Sounds right. I suggest Regexp::Common for finding the url in the text file
use Regexp::Common qw( URI );
/$RE{URI}{HTTP}/
and LWP for checking the links:
use LWP::Simple;
content = get( $url );
die Couldn't get it! unless defined $content;
ping will only tell you if a site is up, not if its webserver is 
available or if a page is available.

Randy.
--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
http://learn.perl.org/ http://learn.perl.org/first-response



Re: IO::Socket for http download

2004-07-02 Thread Ramprasad A Padmanabhan

 LWP requires none of those tools. It does exactly what you are 
 describing: it opens a socket and uses the HTTP protocol to talk to the 
 server.
 
 Randy.
 

Right. Do you have any sample http client script , using IO::Socket
If I get some sample script , my work will be reduced a lot 


Thanks
Ram



-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
http://learn.perl.org/ http://learn.perl.org/first-response




nested if

2004-07-02 Thread Michael S. Robeson II
I came across some code on the internet that looks like this (this is 
only part of the script):

while (align) {
  $line=$_;
if ($line=~/^(.+)/) {
if ($seq) {
$pro{$name}=$seq;
#print SEQ:\n$pro\n\n;
}
$name=$1;
$name=~s/\s//g;
push @names, $name;
#print $name\n;
$k++;
$seq=;
}
else {
chomp $line;
$seq.=$line;
}
}
I am having trouble figuring out how the nested if statements work 
(i.e. what is the order of operation etc...) and their associated else 
statements. I pretty much understand the rest of what is going on but I 
am having trouble putting into words what the nested if statements 
are doing. I mean I know enough that the code is... ummm... yuck!!!   
:-)

-Thanks for any help!
-Mike
--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
http://learn.perl.org/ http://learn.perl.org/first-response



Re: IO::Socket for http download

2004-07-02 Thread Randy W. Sims
Ramprasad A Padmanabhan wrote:
I want to write a basic http download ( text/binary) script using
IO::Socket. Does anyone have any examples anywhere.
I know ,everyone must be wondering why I cant use ready modules like
LWP.
Well I want to auto transfer files to different remote machines. and
these machines ( in all flavors of unix/linux ) dont have tools like
LWP/ftp/wget/lynx etc and I cant install these on the machines
LWP requires none of those tools. It does exactly what you are 
describing: it opens a socket and uses the HTTP protocol to talk to the 
server.

Randy.
--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
http://learn.perl.org/ http://learn.perl.org/first-response



Re: nested if

2004-07-02 Thread Gunnar Hjalmarsson
Michael S. Robeson II wrote:
I came across some code on the internet that looks like this (this
is only part of the script):
while (align) {
  $line=$_;
if ($line=~/^(.+)/) {
if ($seq) {
$pro{$name}=$seq;
#print SEQ:\n$pro\n\n;
}
$name=$1;
$name=~s/\s//g;
push @names, $name;
#print $name\n;
$k++;
$seq=;
}
else {
chomp $line;
$seq.=$line;
}
}
I am having trouble figuring out how the nested if statements
work (i.e. what is the order of operation etc...) and their
associated else statements.
That illustrates the importance of indenting the code in a way that 
makes sense:

while (align) {
$line=$_;
if ($line=~/^(.+)/) {
if ($seq) {
$pro{$name}=$seq;
#print SEQ:\n$pro\n\n;
}
$name=$1;
$name=~s/\s//g;
push @names, $name;
#print $name\n;
$k++;
$seq=;
} else {
chomp $line;
$seq.=$line;
}
}
Quite a difference, isn't it?
--
Gunnar Hjalmarsson
Email: http://www.gunnar.cc/cgi-bin/contact.pl
--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
http://learn.perl.org/ http://learn.perl.org/first-response



RE: :Socket for http download

2004-07-02 Thread NYIMI Jose (BMB)


 -Original Message-
 From: Ramprasad A Padmanabhan 
 [mailto:[EMAIL PROTECTED] 
 Sent: Friday, July 02, 2004 9:58 AM
 To: Randy W. Sims
 Cc: perl beginners
 Subject: Re: :Socket for http download
 
 
 
  LWP requires none of those tools. It does exactly what you are
  describing: it opens a socket and uses the HTTP protocol to 
 talk to the 
  server.
  
  Randy.
  
 
 Right. Do you have any sample http client script , using 
 IO::Socket If I get some sample script , my work will be 
 reduced a lot 
 

Check out lwp cookbook:
http://search.cpan.org/~gaas/libwww-perl-5.800/lwpcook.pod
http://www.perldoc.com/perl5.8.0/lib/lwpcook.html

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]
http://learn.perl.org/ http://learn.perl.org/first-response




Re: IO::Socket for http download

2004-07-02 Thread Ramprasad A Padmanabhan
On Thu, 2004-07-01 at 18:24, Ramprasad A Padmanabhan wrote:
 I want to write a basic http download ( text/binary) script using
 IO::Socket. Does anyone have any examples anywhere.


Thanks all,
I found a basic and excellent example. ( It pays to be patient when
using google)
http://perl.active-venture.com/pod/perlipc-tcpclient.html

Thanks
Ram



-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
http://learn.perl.org/ http://learn.perl.org/first-response




regular expression question

2004-07-02 Thread Graeme McLaren
Afternoon all, I'm trying to to a regular expression to search and replace + 
with \+

I need to escape the + because it is getting used as an operator instead of 
a literal string, this is what I have so far:

$terms[$i] =~ s/\+ /\ \\\+/g;
Basically the result of searching for c++ should return results containing 
that string.

The error I'm getting is this:
DBD::mysql::st execute failed: Got error 'repetition-operator operand 
invalid' from regexp


Any ideas?
Cheers,
G :)
_
Want to block unwanted pop-ups? Download the free MSN Toolbar now!  
http://toolbar.msn.co.uk/

--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
http://learn.perl.org/ http://learn.perl.org/first-response



Re: regular expression question

2004-07-02 Thread Gunnar Hjalmarsson
Graeme McLaren wrote:
Afternoon all, I'm trying to to a regular expression to search and
replace + with \+
I need to escape the + because it is getting used as an operator
instead of a literal string, this is what I have so far:
$terms[$i] =~ s/\+ /\ \\\+/g;
Basically the result of searching for c++ should return results
containing that string.
I'm not sure about what you really need. Please consider the
following:
$_ = 'the c++ programming language';
print '$_ contains c++', \n if /\Qc++/;
s/\+/\\+/g;
print;
Outputs:
$_ contains c++
the c\+\+ programming language
--
Gunnar Hjalmarsson
Email: http://www.gunnar.cc/cgi-bin/contact.pl
--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
http://learn.perl.org/ http://learn.perl.org/first-response



RE: Tie::DBI

2004-07-02 Thread Bob Showalter
David Arnold wrote:
 All,
 
 Never mind. It was a permissions problem. I downloaded the gz file,
 unzipped and untarred and read the installation directions and found
 the problem.

For future reference, you can issue the look command from the CPAN shell:

   $ perl -MCPAN -e shell
   cpan look Tie::DBI

This will download the tarball, untar it into a working directory and drop
you into a shell in that directory.

If you just want to look at the README file, you can use

   cpan readme Tie::DBI

-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
http://learn.perl.org/ http://learn.perl.org/first-response




regexp cleanup

2004-07-02 Thread Laurent Coudeur
Hi,

Trying to clean up a mass of replacement

here is a small bit

$export=~s/\\'F5/õ/gi;
$export=~s/\\'F6/ö/gi;
$export=~s/\\'F7/÷/gi;
$export=~s/\\'F8/ø/gi;
$export=~s/\\'F9/ù/gi;
$export=~s/\\'FA/ú/gi;
$export=~s/\\'FB/û/gi;
$export=~s/\\'FC/ü/gi;

I'd need some pointers on How to tidy the mess (that script is turning into a 
nightmare and I'm running out of braincells)

Laurent Coudeur
353 1 212 3181 

--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
http://learn.perl.org/ http://learn.perl.org/first-response




Re: regexp cleanup

2004-07-02 Thread Gunnar Hjalmarsson
Laurent Coudeur wrote:
Trying to clean up a mass of replacement
here is a small bit
$export=~s/\\'F5/õ/gi;
$export=~s/\\'F6/ö/gi;
$export=~s/\\'F7/÷/gi;
$export=~s/\\'F8/ø/gi;
$export=~s/\\'F9/ù/gi;
$export=~s/\\'FA/ú/gi;
$export=~s/\\'FB/û/gi;
$export=~s/\\'FC/ü/gi;
Try replacing those with:
$export =~ s/\\'(\w\w)/chr hex $1/eg;
perldoc -f hex
perldoc -f chr
--
Gunnar Hjalmarsson
Email: http://www.gunnar.cc/cgi-bin/contact.pl
--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
http://learn.perl.org/ http://learn.perl.org/first-response



Fill a string with zeros.

2004-07-02 Thread Rod Za
Hi all,

Someone knows an way to do this more easy?

_BEGIN_
#!/usr/bin/perl
use warnings;
use strict;
my $job = 15;
my $job_name = 'd0';
print JOBNAME $job_name LENGTH: .length($job_name).\n;
print JOB...: $job  LENGTH: .length($job).\n;
print substr($job_name,-length($job_name),-length($job)).$job.-001\n;
_END_

_RESULT_
JOBNAME d0 LENGTH: 6
JOB...: 1  LENGTH: 1
d1-001
1JOBNAME d0 LENGTH: 6
JOB...: 10  LENGTH: 2
d00010-001
1JOBNAME d0 LENGTH: 6
JOB...: 100  LENGTH: 3
d00100-001
1JOBNAME d0 LENGTH: 6
JOB...: 1000  LENGTH: 4
d01000-001
1JOBNAME d0 LENGTH: 6
JOB...: 1  LENGTH: 5
d1-001
_RESULT_

thank's



__
Do you Yahoo!?
Yahoo! Mail - 50x more storage than other providers!
http://promotions.yahoo.com/new_mail

-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
http://learn.perl.org/ http://learn.perl.org/first-response




RE: regexp cleanup

2004-07-02 Thread Laurent Coudeur

 Thanks it's a lot easier now

-Original Message-
From: Gunnar Hjalmarsson [mailto:[EMAIL PROTECTED] 
Sent: 02 July 2004 14:49
To: [EMAIL PROTECTED]
Subject: Re: regexp cleanup

Laurent Coudeur wrote:
 Trying to clean up a mass of replacement
 
 here is a small bit
 
 $export=~s/\\'F5/õ/gi;
 $export=~s/\\'F6/ö/gi;
 $export=~s/\\'F7/÷/gi;
 $export=~s/\\'F8/ø/gi;
 $export=~s/\\'F9/ù/gi;
 $export=~s/\\'FA/ú/gi;
 $export=~s/\\'FB/û/gi;
 $export=~s/\\'FC/ü/gi;

Try replacing those with:

 $export =~ s/\\'(\w\w)/chr hex $1/eg;

perldoc -f hex
perldoc -f chr

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

--
To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL 
PROTECTED] http://learn.perl.org/ http://learn.perl.org/first-response



--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
http://learn.perl.org/ http://learn.perl.org/first-response




Re: Fill a string with zeros.

2004-07-02 Thread Philipp Traeder
On Friday 02 July 2004 15:55, Rod Za wrote:
 Hi all,

 Someone knows an way to do this more easy?

 _BEGIN_
 #!/usr/bin/perl
 use warnings;
 use strict;
 my $job = 15;
 my $job_name = 'd0';
 print JOBNAME $job_name LENGTH: .length($job_name).\n;
 print JOB...: $job  LENGTH: .length($job).\n;
 print substr($job_name,-length($job_name),-length($job)).$job.-001\n;
 _END_


Hi Rod,

take a look at the sprintf function (perldoc -f sprintf) - something like:

#!/usr/bin/perl -w

use strict;

my $shortnumber = '10';
my $longnumber = '1000';

print sprintf(shortnumber : %06d\n, $shortnumber);
print sprintf(longnumber  : %06d\n, $longnumber);

might do the trick.

BTW: It's easier to help if you specify what you want to do - in this case it 
didn't matter much, but it can take some time to understand what a piece of 
code should be doing... ;-)

HTH,

Philipp

-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
http://learn.perl.org/ http://learn.perl.org/first-response




Re: Fill a string with zeros.

2004-07-02 Thread Rod Za
Hey Philipp, this is was i need! :)

--- Philipp Traeder [EMAIL PROTECTED] wrote:
 On Friday 02 July 2004 15:55, Rod Za wrote:
 Hi Rod,
 
 take a look at the sprintf function (perldoc -f sprintf) - something like:
 
 #!/usr/bin/perl -w
 use strict;
 my $shortnumber = '10';
 my $longnumber = '1000';
 print sprintf(shortnumber : %06d\n, $shortnumber);
 might do the trick.
 
 BTW: It's easier to help if you specify what you want to do - in this case it 
 didn't matter much, but it can take some time to understand what a piece of 
 code should be doing... ;-)

Sorry, i'm not too much clear. What i'm needed is to fill a var (with fix length) with 
zeros and
the sprintf works perfectly. Thank you very much




__
Do you Yahoo!?
New and Improved Yahoo! Mail - 100MB free storage!
http://promotions.yahoo.com/new_mail 

-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
http://learn.perl.org/ http://learn.perl.org/first-response




RE: using the system command

2004-07-02 Thread Adamiec, Larry
OK.  I found the trouble.  It had nothing to do with the system command of
copying or moving the files.  The code snippet below is inside a foreach
loop.  That foreach loop was inside another foreach loop (don't ask) so I
was actually copying the files twice.  That is why the files appeared
identical.

Anyways, I did listen to the advice I was given and removed the system
command.  I am now using file::copy, copy(), and move() functions.

Thanks for the help.



 -Original Message-
 From: Adamiec, Larry 
 Sent: Thursday, July 01, 2004 13:35
 To: '[EMAIL PROTECTED]'
 Subject: using the system command
 
 
 I am running perl version 5.8.0 on a Sun Solaris 9.0 machine.
 
 Given the following bit of code:
 
   $SOME_FILE = $_;
   chomp($SOME_FILE);
   $SOME_SAFE_FILE = $SOME_FILE . _lax;
   system (cp '$SOME_FILE' '$SOME_SAFE_FILE');
   open (IN_FILE, $SOME_FILE );
   open (TMP_OUT_FILE, $tmp_file );
   while (IN_FILE) {
if ( /\\!--/ ) {
 s/(\\!--)(.*)/\\!--  $2/;
 print TMP_OUT_FILE $_;
}
else {
 print TMP_OUT_FILE $_;
}
   }
 
 When I check the contents of $SOME_FILE, I can see that the 
 file has been edited correctly.  However, the contents of 
 $SOME_SAFE_FILE have been edited also.  Given this code, 
 shouldn't $SOME_FILE be different from $SOME_SAFE_FILE?
 
 Lawrence Adamiec
 Unix Manager
 Rm. 525B 
 565 W. Adams St.
 Chicago-Kent College of Law
 Illinois Institute of Technology
 Chicago, Illinois
 312-906-5301
 


RE: Tie::DBI

2004-07-02 Thread David Arnold
Bob,

A good tip. Thanks. :-)

At 08:31 AM 7/2/04 -0400, Bob Showalter wrote:
David Arnold wrote:
 All,
 
 Never mind. It was a permissions problem. I downloaded the gz file,
 unzipped and untarred and read the installation directions and found
 the problem.

For future reference, you can issue the look command from the CPAN shell:

   $ perl -MCPAN -e shell
   cpan look Tie::DBI

This will download the tarball, untar it into a working directory and drop
you into a shell in that directory.

If you just want to look at the README file, you can use

   cpan readme Tie::DBI



-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
http://learn.perl.org/ http://learn.perl.org/first-response




unique array

2004-07-02 Thread perl.org
From http://iis1.cps.unizar.es/Oreilly/perl/cookbook/ch04_07.htm, is this
really the best way to ensure an *ordered* list contains only unique values? 
It seems like it could/should be easier.  I wonder why the examples don't use my.

%seen = ();
@uniq = ();
foreach $item (@list) {
unless ($seen{$item}) {
# if we get here, we have not seen it before
$seen{$item} = 1;
push(@uniq, $item);
}
}
Faster

-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
http://learn.perl.org/ http://learn.perl.org/first-response




RE: help with compiling on win2000 with vs.net

2004-07-02 Thread lonnie percent
I got it finally with some entries in LIB path also. 

I want to thank you, Randy, for all your help. 

Lonnie Percent

-Original Message-
From: Randy W. Sims [mailto:[EMAIL PROTECTED] 
Sent: Thursday, July 01, 2004 11:15 PM
To: lonnie percent
Cc: [EMAIL PROTECTED]
Subject: Re: help with compiling on win2000 with vs.net


lonnie percent wrote:
 INCLUDE=C:\Program Files\Microsoft Visual Studio .NET 
 2003\SDK\v1.1\include\;C:\Program Files\Microsoft Visual Studio 
 .NET\Frame

 LIB=C:\Program Files\Microsoft Visual Studio .NET 
 2003\SDK\v1.1\Lib\;C:\Program Files\Microsoft Visual Studio .NET\Fra 
 meworkSDK\

 *Path is cut off in set. this is path from echo %PATH% 
 C:\PROGRA~1\MICROS~3.NET\Vc7\include

This should not be in PATH; it should be in INCLUDE. It's unclear why 
the vcvars batch file did not set this up correctly. I still use MSVS6, 
so maybe something changed? You might want to check the help files for 
all the batch files in the MSVS directory.

Randy.

-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
http://learn.perl.org/ http://learn.perl.org/first-response





-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
http://learn.perl.org/ http://learn.perl.org/first-response




Re: unique array

2004-07-02 Thread Randy W. Sims
perl.org wrote:
From http://iis1.cps.unizar.es/Oreilly/perl/cookbook/ch04_07.htm, is this
really the best way to ensure an *ordered* list contains only unique values? 
It seems like it could/should be easier.  I wonder why the examples don't use my.

%seen = ();
@uniq = ();
foreach $item (@list) {
unless ($seen{$item}) {
# if we get here, we have not seen it before
$seen{$item} = 1;
push(@uniq, $item);
}
}
Faster
Well, in order to get a uniq list, you /must/ visit every element of the 
list. There are different ways to do this as demonstrated by the 
Cookbook. The only (wee tiny) optimization missed is an optimization 
that applies only to ordered lists: you only need to track the previous 
element in order to determine if the current item is unique. You don't 
need a hash.

The above becomes something like (untested):
my $prev = '';
my @uniq = ();
foreach my $item (@list) {
push(@uniq, $item) unless ($item eq $prev);
$prev = $item;
}
You can also use a 'for' loop and avoid variables all together by simply 
indexing into the array...

Randy.
--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
http://learn.perl.org/ http://learn.perl.org/first-response



RE: unique array

2004-07-02 Thread Bob Showalter
perl.org wrote:
 From http://iis1.cps.unizar.es/Oreilly/perl/cookbook/ch04_07.htm, 

Methinks that stuff is illegally posted copyrighted information.

-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
http://learn.perl.org/ http://learn.perl.org/first-response




Re: unique array

2004-07-02 Thread perl.org
Sorry, I didn't mean ordered as in sorted, I meant ordered as in I don't want
to lose whatever order their in.  But thanks for the tip.

On Fri, 02 Jul 2004 14:26:02 -0400, Randy W. Sims wrote
 perl.org wrote:
 From http://iis1.cps.unizar.es/Oreilly/perl/cookbook/ch04_07.htm, is this
  really the best way to ensure an *ordered* list contains only unique values? 
  It seems like it could/should be easier.  I wonder why the examples don't
use my.
  
  %seen = ();
  @uniq = ();
  foreach $item (@list) {
  unless ($seen{$item}) {
  # if we get here, we have not seen it before
  $seen{$item} = 1;
  push(@uniq, $item);
  }
  }
  Faster
  
 
 Well, in order to get a uniq list, you /must/ visit every element of 
 the list. There are different ways to do this as demonstrated by the 
 Cookbook. The only (wee tiny) optimization missed is an optimization 
 that applies only to ordered lists: you only need to track the 
 previous element in order to determine if the current item is 
 unique. You don't need a hash.
 
 The above becomes something like (untested):
 
 my $prev = '';
 my @uniq = ();
 foreach my $item (@list) {
  push(@uniq, $item) unless ($item eq $prev);
  $prev = $item;
 }
 
 You can also use a 'for' loop and avoid variables all together by 
 simply indexing into the array...
 
 Randy.





-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
http://learn.perl.org/ http://learn.perl.org/first-response




RE: unique array

2004-07-02 Thread perl.org
On Fri, 2 Jul 2004 14:32:49 -0400 , Bob Showalter wrote
 perl.org wrote:
  From http://iis1.cps.unizar.es/Oreilly/perl/cookbook/ch04_07.htm, 
 
 Methinks that stuff is illegally posted copyrighted information.

Several people responded individually with comments like this.  If the authors
care, shouldn't they contact the ISP?  I mean, I can't police the internet
single-handedly.  And I think O'Reilly has probably already made enough take
on this particular snippet...

-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
http://learn.perl.org/ http://learn.perl.org/first-response




RE: unique array

2004-07-02 Thread Bob Showalter
perl.org wrote:
 On Fri, 2 Jul 2004 14:32:49 -0400 , Bob Showalter wrote
  perl.org wrote:
   From http://iis1.cps.unizar.es/Oreilly/perl/cookbook/ch04_07.htm,
  
  Methinks that stuff is illegally posted copyrighted information.
 
 Several people responded individually with comments like this.  If
 the authors care, shouldn't they contact the ISP?  I mean, I can't
 police the internet single-handedly.  And I think O'Reilly has
 probably already made enough take on this particular snippet...

I thought you might be unaware, so wanted to warn you. Evidently, that's not
the case.

-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
http://learn.perl.org/ http://learn.perl.org/first-response




Re: unique array

2004-07-02 Thread Randy W. Sims
perl.org wrote:
On Fri, 2 Jul 2004 14:32:49 -0400 , Bob Showalter wrote
perl.org wrote:
From http://iis1.cps.unizar.es/Oreilly/perl/cookbook/ch04_07.htm, 
Methinks that stuff is illegally posted copyrighted information.

Several people responded individually with comments like this.  If the authors
care, shouldn't they contact the ISP?  I mean, I can't police the internet
single-handedly.  And I think O'Reilly has probably already made enough take
on this particular snippet...
Online versions of many books do appear from time to time on various 
sites. They generally move around. I've found this out by stumbling 
across them during google searches, and then going back to that link a 
day or two later and finding it gone.

Anyway, it is illegal. It is obviously so. You don't have to police the 
internet. You only have to police your own behaviour.

Randy.
--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
http://learn.perl.org/ http://learn.perl.org/first-response



Copyright Violation - RE: unique array

2004-07-02 Thread Bakken, Luke
 On Fri, 2 Jul 2004 14:32:49 -0400 , Bob Showalter wrote
  perl.org wrote:
   From http://iis1.cps.unizar.es/Oreilly/perl/cookbook/ch04_07.htm, 
  
  Methinks that stuff is illegally posted copyrighted information.
 
 Several people responded individually with comments like 
 this.  If the authors
 care, shouldn't they contact the ISP?  I mean, I can't police 
 the internet
 single-handedly.  And I think O'Reilly has probably already 
 made enough take
 on this particular snippet...

How nice of you to decide this for O'Reilly.

I think the local grocery store has made enough money for today, and I
think I'll go in and take an apple.

 I mean, I can't police 
 the internet
 single-handedly.

No, but you can at least refrain from posting links to copyrighted
material to the beginners list.

--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
http://learn.perl.org/ http://learn.perl.org/first-response




Help with HASH.

2004-07-02 Thread Rod Za
Hello all,

I want to make a function to list all jobs name from a printer.
The format of the jobs name is like d1-001, d2-001.
To list all the jobs and get the correct job name, i use the lpstat command, that 
returns me lines
like this one: 
_DATA_
HP4100V-4   rodza  2597888   Seg 21 Jun 2004 12:56:56 BRT
_DATA_

in the first camp i got the printer name (HP4100V) followed by the job numer 
(separated by -), the
owner of the job, the job length in bytes and the started job data.

What i mean here is to use a hash with 2 camps: 'name' and 'jobs'. In the 'name' i put 
the printer
name. In the 'jobs' i put a hash reference that got the job name like his key 
associated with the
owner job name.

well, i write this code that are not working::

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

sub lst_job{ # this sub list all the jobs name from a printer
my ($printer) = @_;
my @lpstat = `lpstat -P $printer`;
my %jobs;
#here i assembly the job name (like d1-01) 
for(my $i=0; $i  @lpstat; $i++){
$lpstat[$i] =~ /\w+\-(\d+)\s+(\w+)\s+/;
$jobs{sprintf(d%05d-001,$1)} = $2;
} 
my %printer = ( name = $printer,
jobs = \%jobs,
);
   return %printer;
}

my %printers = lst_job(HP4100V);
print The printers: .$printers{name}. got this job(s):\n;
foreach my $keys (keys $printers{jobs}){
print $printers{jobs}-{$key}.\n;
};
_END_

this is the error i got:

_ERROR_
Type of arg 1 to keys must be hash (not hash element) at printer.pm line 61, near })
_ERROR_

Can someone help me?

Thanks



__
Do you Yahoo!?
Yahoo! Mail Address AutoComplete - You start. We finish.
http://promotions.yahoo.com/new_mail 

-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
http://learn.perl.org/ http://learn.perl.org/first-response




Re: Copyright Violation - RE: unique array

2004-07-02 Thread perl.org
Hmm, if I hadn't posted the link at least one person would have told me to
check the docs.  But I guess there are more useless responses if I do post the
link.  So next time please don't ask me to check the docs.

Why doesn't someone go police google then - they gave me the link.



-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
http://learn.perl.org/ http://learn.perl.org/first-response




Re: Copyright Violation - RE: unique array

2004-07-02 Thread u235sentinel

Bakken, Luke wrote:
How nice of you to decide this for O'Reilly.
I think the local grocery store has made enough money for today, and I
think I'll go in and take an apple.
Why just an apple?  Why not a big fat steak?  It doesn't have to end 
there also, maybe I can come back for dessert later :-)
It's easy to justify anything these days.  Doesn't make it right. 

I mean, I can't police 
the internet
single-handedly.
   

No, but you can at least refrain from posting links to copyrighted
material to the beginners list.
 

Somebody screwed up and violated the copyright laws by publishing those 
awesome books.  Let's support good authors and their works by purchasing 
them.  Publishing the links anywhere doesn't further better products.  
That's why the copyright laws exist.


Re: unique array

2004-07-02 Thread Randy W. Sims
perl.org wrote:
Sorry, I didn't mean ordered as in sorted, I meant ordered as in I don't want
to lose whatever order their in.  But thanks for the tip.
Oops. There's been a lot of discussions on sorting lately, and I guess I 
mis-associated.

Anyway, my previous arguement still applies. You have to iterate over 
each element and determine if it has been seen before. The method you 
posted is as good as any. It does everything explicitly, so you can see 
what it's doing. On the other hand, I've always liked the grep method. I 
can't remember off-hand which is faster. They both perform exactly the 
same operations of iterating and comparing, but the grep method is a 
little less verbose.

On Fri, 02 Jul 2004 14:26:02 -0400, Randy W. Sims wrote
perl.org wrote:
From http://iis1.cps.unizar.es/Oreilly/perl/cookbook/ch04_07.htm, is this
really the best way to ensure an *ordered* list contains only unique values? 
It seems like it could/should be easier.  I wonder why the examples don't
use my.
%seen = ();
@uniq = ();
foreach $item (@list) {
   unless ($seen{$item}) {
   # if we get here, we have not seen it before
   $seen{$item} = 1;
   push(@uniq, $item);
   }
}
Faster
Well, in order to get a uniq list, you /must/ visit every element of 
the list. There are different ways to do this as demonstrated by the 
Cookbook. The only (wee tiny) optimization missed is an optimization 
that applies only to ordered lists: you only need to track the 
previous element in order to determine if the current item is 
unique. You don't need a hash.

The above becomes something like (untested):
my $prev = '';
my @uniq = ();
foreach my $item (@list) {
push(@uniq, $item) unless ($item eq $prev);
$prev = $item;
}
You can also use a 'for' loop and avoid variables all together by 
simply indexing into the array...

Randy.




--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
http://learn.perl.org/ http://learn.perl.org/first-response



Re: Copyright Violation - RE: unique array

2004-07-02 Thread Wiggins d Anconia
 Hmm, if I hadn't posted the link at least one person would have told me to
 check the docs.  But I guess there are more useless responses if I do
post the
 link.  So next time please don't ask me to check the docs.
 

There are free docs available, I don't think anyone has ever suggested
checking a copyright violating doc.

 Why doesn't someone go police google then - they gave me the link.
 

Have you missed all of the P2P discussions?  Google polices itself
already more than many would like...

http://danconia.org


-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
http://learn.perl.org/ http://learn.perl.org/first-response




Re: Help with HASH.

2004-07-02 Thread Wiggins d Anconia
 Hello all,
 
 I want to make a function to list all jobs name from a printer.
 The format of the jobs name is like d1-001, d2-001.
 To list all the jobs and get the correct job name, i use the lpstat
command, that returns me lines
 like this one: 
 _DATA_
 HP4100V-4   rodza  2597888   Seg 21 Jun 2004
12:56:56 BRT
 _DATA_
 
 in the first camp i got the printer name (HP4100V) followed by the job
numer (separated by -), the
 owner of the job, the job length in bytes and the started job data.
 
 What i mean here is to use a hash with 2 camps: 'name' and 'jobs'. In
the 'name' i put the printer
 name. In the 'jobs' i put a hash reference that got the job name like
his key associated with the
 owner job name.
 
 well, i write this code that are not working::
 
 _BEGIN_
 #!/usr/bin/perl
 use warnings;
 use strict;

Excellent start...

 
 sub lst_job{ # this sub list all the jobs name from a printer
 my ($printer) = @_;
 my @lpstat = `lpstat -P $printer`;
 my %jobs;
 #here i assembly the job name (like d1-01) 
 for(my $i=0; $i  @lpstat; $i++){
 $lpstat[$i] =~ /\w+\-(\d+)\s+(\w+)\s+/;
 $jobs{sprintf(d%05d-001,$1)} = $2;
 } 

This will work and is very Cesque, to make it more Perlish you might
consider a foreach loop,

foreach my $job (@lpstat) {
  $job =~ /./;
   blah blah blah...
}

For me it is a bit more readable, but to each their own.

 my %printer = ( name = $printer,
 jobs = \%jobs,
 );
return %printer;
 }
 
 my %printers = lst_job(HP4100V);
 print The printers: .$printers{name}. got this job(s):\n;
 foreach my $keys (keys $printers{jobs}){

In the above line, as the error suggests 'keys' must take a hash as its
argument, $printers{jobs} is a scalar, so essentially you need to
dereference its value back into a hash, ending up with,

foreach my $keys (keys %{ $printers{jobs} }) {
...

 print $printers{jobs}-{$key}.\n;

If you use $keys in the loop, then $key will throw a syntax error with
strict on, one should be plural the other shouldn't, which I was going
to suggest for readability anyways (aka make $key singular).

 };
 _END_
 
 this is the error i got:
 
 _ERROR_
 Type of arg 1 to keys must be hash (not hash element) at printer.pm
line 61, near })
 _ERROR_
 
 Can someone help me?
 

HTH,

http://danconia.org


-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
http://learn.perl.org/ http://learn.perl.org/first-response




Still having problems installing MIME::Lite locally.

2004-07-02 Thread jason corbett
Here is where I am in the process:
 
I have MIME::Lite located on the server in a folder called 
/home/samcsm/jcorbett/myperl/lib
 
I use this simple script to test out emailing a query below and get the error stating 
that cannot find MIME/Lite.pm' anywhere.
 
Now mind you I have MIME/Lite.pm installed in 
 
/home/samcsm/jcorbett/myperl/lib/perl5/site_perl/MIME/Lite.pm
 
Can you tell me whats wrong?

#!/usr/bin/perl 
use warnings;
use strict;
use DBI;
use MIME::Lite;
 
BEGIN{
unshift (@INC, '/home/samcsm/jason/myperl/lib/perl5/site_perl/MIME/Lite.pm');}
 
$ENV{ORACLE_HOME}=/orav101/oracle/8.0.6; 

#Gather data for connecting to database:
 

our ($sql);
our ($sth);
our ($dbh);
our (@record);
our (@files);
our ($filename);
our ($recordlist);
our $database_temp=dbi:Oracle:#;
our $username=#;
our $passwd=#;

 
$dbh = DBI-connect($database_temp, $username, $passwd) or  
$dbh-{RaiseError} = 1;
 
 
#Set up your sql statement that you want to run in Oracle
 
 $sql=qq( select * from bill where rownum 100);

$sth=$dbh-prepare($sql);
 
#Execute the SQL statememt

$sth-execute();
 
 
while(@record= $sth-fetchrow_array())

 { 
 
 $recordlist=join(|,@record);
 }
 
$sth-finish;

$dbh-disconnect;
 
 my $message=MIME::Lite-new(

From:  ='[EMAIL PROTECTED]',

To:  ='[EMAIL PROTECTED]',

Subject: ='This is a test of the MIME::Lite Mod',
   
 Data  =$recordlist
 
);
 
 
$message-send;
 

 
 
 /home/samcsm/jcorbett/myperl/lib/perl5/site_perl/MIME/Lite.pm


Re: Still having problems installing MIME::Lite locally.

2004-07-02 Thread Randy W. Sims
jason corbett wrote:
Here is where I am in the process:
 
I have MIME::Lite located on the server in a folder called /home/samcsm/jcorbett/myperl/lib
 
I use this simple script to test out emailing a query below and get the error stating that cannot find MIME/Lite.pm' anywhere.
 
Now mind you I have MIME/Lite.pm installed in 
 
/home/samcsm/jcorbett/myperl/lib/perl5/site_perl/MIME/Lite.pm
 
Can you tell me whats wrong?

#!/usr/bin/perl 
use warnings;
use strict;
use DBI;
use MIME::Lite;
 
BEGIN{
unshift (@INC, '/home/samcsm/jason/myperl/lib/perl5/site_perl/MIME/Lite.pm');}
unshift (@INC, '/home/samcsm/jason/myperl/lib/perl5/site_perl/');}
or more simply
use lib '/home/samcsm/jason/myperl/lib/perl5/site_perl/';
use MIME::Lite;
--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
http://learn.perl.org/ http://learn.perl.org/first-response



Re: Help with HASH.

2004-07-02 Thread Rod Za

--- Wiggins d Anconia [EMAIL PROTECTED] wrote:
[snip]
  _BEGIN_
  #!/usr/bin/perl
  use warnings;
  use strict;
 
 Excellent start...

:) thank you

[snip]
  for(my $i=0; $i  @lpstat; $i++){
  $lpstat[$i] =~ /\w+\-(\d+)\s+(\w+)\s+/;
  $jobs{sprintf(d%05d-001,$1)} = $2;
  } 
 
 This will work and is very Cesque, to make it more Perlish you might
 consider a foreach loop,
 
 foreach my $job (@lpstat) {
   $job =~ /./;
blah blah blah...
 }
 
 For me it is a bit more readable, but to each their own.

:) i'm accustoming with perl :) sometimes foreach makes me confused :)

[snip]
 In the above line, as the error suggests 'keys' must take a hash as its
 argument, $printers{jobs} is a scalar, so essentially you need to
 dereference its value back into a hash, ending up with,
 
 foreach my $keys (keys %{ $printers{jobs} }) {
[snip]

Was that! Every time a hash reference is returned i need to derefence! Oh! god! 
Is this kind of reference like the C pointer, or something like this?

 ...
 
  print $printers{jobs}-{$key}.\n;
 
 If you use $keys in the loop, then $key will throw a syntax error with
 strict on, one should be plural the other shouldn't, which I was going
 to suggest for readability anyways (aka make $key singular).
[snip again]

Wiggins, thank you very much! 





__
Do you Yahoo!?
New and Improved Yahoo! Mail - 100MB free storage!
http://promotions.yahoo.com/new_mail 

-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
http://learn.perl.org/ http://learn.perl.org/first-response




Re: Help with HASH.

2004-07-02 Thread Wiggins d Anconia
 
 --- Wiggins d Anconia [EMAIL PROTECTED] wrote:
 [snip]
 [snip]
  In the above line, as the error suggests 'keys' must take a hash as its
  argument, $printers{jobs} is a scalar, so essentially you need to
  dereference its value back into a hash, ending up with,
  
  foreach my $keys (keys %{ $printers{jobs} }) {
 [snip]
 
 Was that! Every time a hash reference is returned i need to derefence!
Oh! god! 
 Is this kind of reference like the C pointer, or something like this?
 

You only have to dereference if you are trying to do something to the
structure in aggregate, aka you have to supply a hash, such as is the
case for 'keys', 'values', and 'each'.  If you want to access a single
value from the nested hash, you can access it directly using the little
arrow syntax,

$printers-{jobs}-{4};

For instance would access the value with key '4' in the jobs hash of the
printers hash.

References are similar to C's pointers, more and less powerful in most
of the same ways everything else is in Perl as compared to C. The key
big one that I have heard of, is that there is no pointer (reference)
arithmetic in Perl as in C.  As I am not a C guy this is where my
elaboration ends, if you have more specific pointer/ref questions be
sure to ask, someone with more C experience will surely answer. 

For much more on refs check out,

perldoc perlreftut
perldoc perlref
perldoc perllol
perldoc perldsc

snip

And the excellent Learning Perl Objs, Refs, and Mods from ORA.

http://danconia.org

-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
http://learn.perl.org/ http://learn.perl.org/first-response




Re: Help with HASH.

2004-07-02 Thread Wiggins d Anconia
  
  --- Wiggins d Anconia [EMAIL PROTECTED] wrote:
  [snip]
  [snip]
   In the above line, as the error suggests 'keys' must take a hash
as its
   argument, $printers{jobs} is a scalar, so essentially you need to
   dereference its value back into a hash, ending up with,
   
   foreach my $keys (keys %{ $printers{jobs} }) {
  [snip]
  
  Was that! Every time a hash reference is returned i need to derefence!
 Oh! god! 
  Is this kind of reference like the C pointer, or something like this?
  
 
 You only have to dereference if you are trying to do something to the
 structure in aggregate, aka you have to supply a hash, such as is the
 case for 'keys', 'values', and 'each'.  If you want to access a single
 value from the nested hash, you can access it directly using the little
 arrow syntax,
 
 $printers-{jobs}-{4};

Dammit, $printers is not a hash reference, so the above will not work
(boy everyone can see how I normally do it ;-)), for your example that
should read,

$printers{jobs}-{4};

Which going back to your post, I see you already had. Sorry for the noise,

http://danconia.org


-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
http://learn.perl.org/ http://learn.perl.org/first-response




Re: Still having problems installing MIME::Lite locally.

2004-07-02 Thread Gunnar Hjalmarsson
Jason Corbett wrote:
I use this simple script to test out emailing a query below and get
the error stating that cannot find MIME/Lite.pm' anywhere.
Now mind you I have MIME/Lite.pm installed in
/home/samcsm/jcorbett/myperl/lib/perl5/site_perl/MIME/Lite.pm
Can you tell me whats wrong?
#!/usr/bin/perl
use warnings;
use strict;
use DBI;
use MIME::Lite;
BEGIN{ unshift (@INC,
'/home/samcsm/jason/myperl/lib/perl5/site_perl/MIME/Lite.pm');}
As Randy mentioned, you are adding the wrong path to @INC. But I think 
there is one more thing that is not correct here: Even if you put that 
statement in a BEGIN block, you must not have use MIME::Lite; before 
the statement. Both use statements and statements in BEGIN blocks 
are executed at compile time, but the order still matters. So either:

BEGIN {unshift @INC, '/home/samcsm/jason/myperl/lib/perl5/site_perl'}
use MIME::Lite;
or
use lib '/home/samcsm/jason/myperl/lib/perl5/site_perl';
use MIME::Lite;
--
Gunnar Hjalmarsson
Email: http://www.gunnar.cc/cgi-bin/contact.pl
--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
http://learn.perl.org/ http://learn.perl.org/first-response



Re: Help with HASH.

2004-07-02 Thread Rod Za
--- Wiggins d Anconia [EMAIL PROTECTED] wrote:
  You only have to dereference if you are trying to do something to the
  structure in aggregate, aka you have to supply a hash, such as is the
  case for 'keys', 'values', and 'each'.  If you want to access a single
  value from the nested hash, you can access it directly using the little
  arrow syntax,
  
  $printers-{jobs}-{4};

Yes, now i got it.

 
 Dammit, $printers is not a hash reference, so the above will not work
 (boy everyone can see how I normally do it ;-)), for your example that
 should read,
 
 $printers{jobs}-{4};

Using my example, the followed works perfectly:

$printers{jobs}-{'d00011-001'};


 Which going back to your post, I see you already had. Sorry for the noise,

Thank you very much Wiggins.



__
Do you Yahoo!?
Read only the mail you want - Yahoo! Mail SpamGuard.
http://promotions.yahoo.com/new_mail 

-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
http://learn.perl.org/ http://learn.perl.org/first-response




Re: Help with HASH.

2004-07-02 Thread Rod Za
Wiggins,

just one more thing, how can i get the number of elements from an hash like this one 
that i'm
trying to use?

--- Wiggins d Anconia [EMAIL PROTECTED] wrote:
foreach my $keys (keys %{ $printers{jobs} }) {




__
Do you Yahoo!?
New and Improved Yahoo! Mail - Send 10MB messages!
http://promotions.yahoo.com/new_mail 

-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
http://learn.perl.org/ http://learn.perl.org/first-response




Re: Help with HASH.

2004-07-02 Thread Wiggins d Anconia
 Wiggins,
 
 just one more thing, how can i get the number of elements from an hash
like this one that i'm
 trying to use?
 
 foreach my $keys (keys %{ $printers{jobs} }) {

You can take the list in a scalar context, or force it into a scalar
context, such as,

my $num = keys %{ $printers{jobs} };

or the more verbose,

my $num = scalar keys %{ $printers{jobs} };

'values' works in place of 'keys' since it is a 1-to-1 relationship,
keys is my preferred.

http://danconia.org


-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
http://learn.perl.org/ http://learn.perl.org/first-response




Re: Still having problems installing MIME::Lite locally.

2004-07-02 Thread Randy W. Sims
jason corbett wrote:
So I am sure whats going on, can you elaborate on why this is the fix? 
For example, the error asked for MIME/Lite.pm so I gave it the path to 
the file. Here you are stating that I should just go up to the point 
where I am mapping:
 
/home/samcsm/jason/myperl/lib/perl5/site_perl/
Basically (I'm omitting some advanced techniques here), @INC contains a 
set of directories (and CODEREFs). Those directories are searched when a 
module is used/required. The way perl searches is basically

1. $module_name =~ s/::/$pathsep/
   eg MIME::Lite becomes MIME/Lite
2. append extension
   eg MIME/Lite.pm
3. foreach $dir in @INC
 if -e $dir/MIME/Lite.pm
   load it
 end if
   end foreach
   die if no module found
Actually, I think there is a better psuedo code example in `perldoc -f 
require`


*/Randy W. Sims [EMAIL PROTECTED]/* wrote:
jason corbett wrote:
  Here is where I am in the process:
 
  I have MIME::Lite located on the server in a folder called
/home/samcsm/jcorbett/myperl/lib
 
  I use this simple script to test out emailing a query below and
get the error stating that cannot find MIME/Lite.pm' anywhere.
 
  Now mind you I have MIME/Lite.pm installed in
 
  /home/samcsm/jcorbett/myperl/lib/perl5/site_perl/MIME/Lite.pm
 
  Can you tell me whats wrong?
 
  #!/usr/bin/perl
  use warnings;
  use strict;
  use DBI;
  use MIME::Lite;
 
  BEGIN{
  unshift (@INC,
'/home/samcsm/jason/myperl/lib/perl5/site_perl/MIME/Lite.pm');}
unshift (@INC, '/home/samcsm/jason/myperl/lib/perl5/site_perl/');}
or more simply
use lib '/home/samcsm/jason/myperl/lib/perl5/site_perl/';
use MIME::Lite;

--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
http://learn.perl.org/ http://learn.perl.org/first-response



Re: Help with HASH.

2004-07-02 Thread John W . Krahn
On Friday 02 July 2004 12:05, Rod Za wrote:

 Hello all,

Hello,

 I want to make a function to list all jobs name from a printer.
 The format of the jobs name is like d1-001, d2-001.
 To list all the jobs and get the correct job name, i use the lpstat
 command, that returns me lines like this one:
 _DATA_
 HP4100V-4   rodza  2597888   Seg 21 Jun 2004
 12:56:56 BRT _DATA_

 in the first camp i got the printer name (HP4100V) followed by the
 job numer (separated by -), the owner of the job, the job length in
 bytes and the started job data.

 What i mean here is to use a hash with 2 camps: 'name' and 'jobs'. In
 the 'name' i put the printer name. In the 'jobs' i put a hash
 reference that got the job name like his key associated with the
 owner job name.

 well, i write this code that are not working::

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

 sub lst_job{ # this sub list all the jobs name from a printer
 my ($printer) = @_;
 my @lpstat = `lpstat -P $printer`;
 my %jobs;
 #here i assembly the job name (like d1-01)
 for(my $i=0; $i  @lpstat; $i++){

You can just use a foreach loop here:

foreach ( @lpstat ) {


 $lpstat[$i] =~ /\w+\-(\d+)\s+(\w+)\s+/;
 $jobs{sprintf(d%05d-001,$1)} = $2;

You shouldn't use the numeric variables unless the regular expression 
matched successfully and you should anchor the regexp so it doesn't 
match the wrong thing.

$jobs{ sprintf 'd%05d-001', $1 } = $2
if /^\w+-(\d+)\s+(\w+)\s+/;


 }
 my %printer = ( name = $printer,
 jobs = \%jobs,
 );
return %printer;

You don't need to create a hash here, just return the list.

return name = $printer, jobs = \%jobs;


 }

You could write it like this:   :-)

sub lst_job {
my $printer = shift;
my $flag;
return name = $printer, jobs = {
map +( $flag = !$flag ) ? sprintf( 'd%05d-001', $_ ) : $_,
map /^\w+-(\d+)\s+(\w+)\s+/,
`lpstat -P $printer`
}
}


 my %printers = lst_job(HP4100V);
 print The printers: .$printers{name}. got this job(s):\n;

Perl will interpolate scalars in strings.

print The printers: $printers{name} got this job(s):\n;


 foreach my $keys (keys $printers{jobs}){

You need to dereference the hash reference in $printers{jobs}.

for my $key ( keys %{ $printers{ jobs } } ) {


 print $printers{jobs}-{$key}.\n;

The '-' is optional in this instance.

print $printers{jobs}{$key}\n;


 };
 _END_


John
-- 
use Perl;
program
fulfillment


-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
http://learn.perl.org/ http://learn.perl.org/first-response




Re: Help with HASH.

2004-07-02 Thread Randy W. Sims
Wiggins d Anconia wrote:
Wiggins,
just one more thing, how can i get the number of elements from an hash
like this one that i'm
trying to use?

foreach my $keys (keys %{ $printers{jobs} }) {

You can take the list in a scalar context, or force it into a scalar
context, such as,
my $num = keys %{ $printers{jobs} };
or the more verbose,
my $num = scalar keys %{ $printers{jobs} };
'values' works in place of 'keys' since it is a 1-to-1 relationship,
keys is my preferred.
Don't forget the oft forgot and more efficient
print scalar %hash;
eg.
my %hash = (
  A = 1, B = 2, C = 3
);
print scalar %hash;
= 3/8
Randy.
--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
http://learn.perl.org/ http://learn.perl.org/first-response



Re: Help with HASH.

2004-07-02 Thread John W . Krahn
On Friday 02 July 2004 15:07, Randy W. Sims wrote:
 Wiggins d Anconia wrote:
 
  You can take the list in a scalar context, or force it into a
  scalar context, such as,
 
  my $num = keys %{ $printers{jobs} };
 
  or the more verbose,
 
  my $num = scalar keys %{ $printers{jobs} };
 
  'values' works in place of 'keys' since it is a 1-to-1
  relationship, keys is my preferred.

 Don't forget the oft forgot and more efficient

 print scalar %hash;

 eg.

 my %hash = (
A = 1, B = 2, C = 3
 );
 print scalar %hash;
 = 3/8

Neither the 3 nor the 8 nor 3 divided by 8 has any relation to the 
number of keys or number of values in the hash.


John
-- 
use Perl;
program
fulfillment

-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
http://learn.perl.org/ http://learn.perl.org/first-response




Re: Help with HASH.

2004-07-02 Thread Randy W. Sims
John W. Krahn wrote:
On Friday 02 July 2004 15:07, Randy W. Sims wrote:
Wiggins d Anconia wrote:
You can take the list in a scalar context, or force it into a
scalar context, such as,
my $num = keys %{ $printers{jobs} };
or the more verbose,
my $num = scalar keys %{ $printers{jobs} };
'values' works in place of 'keys' since it is a 1-to-1
relationship, keys is my preferred.
Don't forget the oft forgot and more efficient
print scalar %hash;
eg.
my %hash = (
  A = 1, B = 2, C = 3
);
print scalar %hash;
= 3/8

Neither the 3 nor the 8 nor 3 divided by 8 has any relation to the 
number of keys or number of values in the hash.
D'oh, you're right, of course. I was thinking it returned number of 
elements/number of buckets; it's really number of used buckets/number 
of allocated buckets or false if there are no elements. Shows how much 
I use the feature (and that I should really check more before posting).

Thanks for the correction,
Randy. (who confuses more than clarifies lately)
--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
http://learn.perl.org/ http://learn.perl.org/first-response



Can't install Tk.pm

2004-07-02 Thread Jeff Borders
Hello,

I'm trying to install Tk and get the error listed below.  I'm running
Fedora Core 1.  What does it mean and how can I fix it?  I've tried with
perl -MCPAN -e shell, then install Tk, and also downloading the tarball.

Thanks,

jeffatjeffborders.com  

t/Trace..ok
t/trace1.ok
t/widget.ok
t/wm-timeok
t/wm.ok
t/X..ok
t/zzHListok
t/zzPhotook
t/zzScrolled.NOK 66# Test 66 got: '589x341+0+32'
(t/zzScrolled.t at line 104 fail #2)
#Expected: '589x341+0+0' (Sizechk: geometry has not changed not
reset for -height = 24+(5))
#  t/zzScrolled.t line 104 is: ok($newgeo, $oldgeo,
Sizechk: geometry has not changed not reset .
t/zzScrolled.NOK 94# Test 94 got: '589x341+17+32'
(t/zzScrolled.t at line 104 fail #4)
#Expected: '589x341+0+32' (Sizechk: geometry has not changed not
reset for -width = 80+(5))
t/zzScrolled.FAILED tests 66, 94
Failed 2/94 tests, 97.87% okay
t/zzText.ok
t/zzTixGrid..ok
Failed TestStat Wstat Total Fail  Failed  List of Failed
---
t/zzScrolled.t   942   2.13%  66 94
 (3 subtests UNEXPECTEDLY SUCCEEDED), 23 subtests skipped.
Failed 1/47 test scripts, 97.87% okay. 2/2619 subtests failed, 99.92%
okay.
make: *** [test_dynamic] Error 255



-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
http://learn.perl.org/ http://learn.perl.org/first-response




Re: unique array

2004-07-02 Thread Jeff 'japhy' Pinyan
On Jul 2, perl.org said:

From http://iis1.cps.unizar.es/Oreilly/perl/cookbook/ch04_07.htm, is
this really the best way to ensure an *ordered* list contains only unique
values?  It seems like it could/should be easier.  I wonder why the
examples don't use my.

If you want a more transparent approach, use my Tie::Array::Unique module.

  use Tie::Array::Unique;
  tie my(@array), 'Tie::Array::Unique';

Now use @array normally.  It will never contain duplicate elements.

Get it from CPAN.

-- 
Jeff japhy Pinyan  [EMAIL PROTECTED]  http://www.pobox.com/~japhy/
RPI Acacia brother #734   http://www.perlmonks.org/   http://www.cpan.org/
CPAN ID: PINYAN[Need a programmer?  If you like my work, let me know.]
stu what does y/// stand for?  tenderpuss why, yansliterate of course.


-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
http://learn.perl.org/ http://learn.perl.org/first-response