Re: Automatically write in uppercase

2004-03-02 Thread zsdc
Paul Johnson wrote:

James Edward Gray II said:

On Feb 29, 2004, at 6:30 AM, John wrote:

That's a nice method but i would prefer to activate the CAPS-LOCK and
user
write in capitals in my text entry widget
I would prefer you didn't.  ;)

The keyboard takes commands from me, not the computer.  If a program
started monkeying with my control of such a device, it would find my
trash can, mighty quick.
Come on people.  Maybe John has a good reason for wanting Caps Lock to be on.
I don't think anyone said the caps lock should never be on. We were only 
saying that it should be controlled by the user, who can turn it on or 
off whenever she wants.

I have solved this by accepting lowercase input as uppercase, and in my
case this works well as I am not using a text entry widget, but a Caps
Lock solution might also be nice.  Unfortunately, I don't think a cross
platform solution exists, but if anyone knows of one, or if John tells us
which platform he is concerned about and anyone knows of a solution for
that platform, please speak up.
You might always ask the user to turn it on if it was off, if that is 
really necessary. That is the only cross-platform solution I can think 
about.
--
ZSDC

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



Re: Threads in Perl

2004-03-02 Thread WC -Sx- Jones
Tim Johnson wrote:
Can anyone give me a quick hint as to where to find documentation on how
to use threads w/Perl?  


CPAN is best to start off with -- that way you develop better questions =)

http://search.cpan.org/search?query=Threads&mode=all

-Bill-
__Sx__
http://youve-reached-the.endoftheinternet.org/
--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
 



Re: listing prime numbers in a range (Beginning Perl exercise)

2004-03-02 Thread James Edward Gray II
On Mar 2, 2004, at 5:38 PM, Stuart White wrote:

--- James Edward Gray II <[EMAIL PROTECTED]>
wrote:
It makes perfect sense, yes, but I'm still missing
one piece of
information, the broken code you would like fixed.
As I said in my
last message, "...just post that nested foreach and
let us help you fix
it."
My mistake, I thought I had pasted into my message.
Here it is:
Stuart, can we please see the whole script?

James

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



Re: interacting with table layouts using DBI

2004-03-02 Thread Andrew Gaffney
Andrew Gaffney wrote:
Is there an easy way with DBI (or anything other modules) to retrieve 
and modify the layout of database tables in a MySQL DB? I need to write 
a program to add 2 fields to ~40 tables with an identical layout. The 
tables are named "m"mmyy where "m" is an actual 'm', mm is a 2 digit 
month, and  is a 4 digit year. If the table doesn't exist, I want to 
create it with the same layout as all the rest. I can write a program 
that does this the hard way, but before I started, I wanted to know if 
there was an easier way.
To add/modify my query: Is there a module in existance that can act as a wrapper for table 
structures in a MySQL (or any other) DB? I'm thinking about writing a module that uses a 
tied hash (which will be a hash of hash references corresponding to different properties 
of each field). If one doesn't exist, I'd like to atleast try my hand at creating 
something like this for easily adding and modifying tables via DBI.

--
Andrew Gaffney
Network Administrator
Skyline Aeronautics, LLC.
636-357-1548
--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
 



Re: Trainset - initial release

2004-03-02 Thread R. Joseph Newton
Gary Stainburn wrote:

>
> return barf("some message") if (some condition);
>
> combining the if/print and the return in one. This would mean that the return
> would have to return from 2 subs (barf and he caller).
>
> I don't know if this is possible,

Sure.  Just be kind to yourself, and have barf() return a meaningful value, such
as, in this case, an explicit undef or 0.  Have the outer sub return a true value
if the nauseous condition does not occur.  That way, the caller of the outer sub
can read a true return value if it doesn't barf.  Very useful for error-trapping.

Joseph



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




Re: Trainset - initial release

2004-03-02 Thread R. Joseph Newton
James Edward Gray II wrote:

> On Mar 1, 2004, at 3:59 AM, Gary Stainburn wrote:
>
> > Okay, I can do that simply enough, but could you elaborate on the
> > reason
> > please.
>
> Sure.
>
> Subroutines may be called recursively.  If a subroutine iscalled using
>
> the "&" form, the argument list is optional, and if omitted, no @_
> array is set up for the subroutine: the @_ array at the time of the
> call is visible to subroutine instead.  This is an efficiency
> mechanism
> that new users may wish to avoid.
>
> That's a quote from 'perldoc perlsub', which does a far better job of
> explaining these things than I could.  It's worth a look.

I must say, I was sort of mystified, in reading this, as to why one would want
to do this in a recursive subroutine.  I guess it might just be different
recusrion styles.  For me, it is the change in arguments as a subroutine calls
itself that powers the work, and that leads to the stopping case[s].

It might be interesting to see an example of a recursive call that retained its
pparameter list, with or without the use of the syntactic shortcut.

Joseph



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




Re: How to capture pid

2004-03-02 Thread John W. Krahn
Harry Putnam wrote:
> 
> "John W. Krahn" <[EMAIL PROTECTED]> writes:
> 
> > open FILE, '>file' or die "Cannot open file: $!";
> > my $pid = open DUMP, 'tcpdump -v -ieth0 |' or die "Cannot open pipe from
> > tcpdump: $!";
> > print FILE while ;
> > close DUMP or die "Cannot close pipe from tcpdump: $!";
> > close FILE;
> >
> > print "Pid was $pid\n";
> 
> Looking at this, I'm guessing one doesn't get to know the pid until
> its all over.  (I can't try it out right now).  Which in this case
> would not be usefull.

You can print the PID before the loop starts:

open FILE, '>file' or die "Cannot open file: $!";
my $pid = open DUMP, 'tcpdump -v -ieth0 |' or die "Cannot open pipe from
tcpdump: $!";
print "Pid is $pid\n";

print FILE while ;
close DUMP or die "Cannot close pipe from tcpdump: $!";
close FILE;


> This thing needs to run until at the 4hr mark syslog sends a SIGHUP
> and rotates the ouput files.  All that is taken care of by syslog.
> 
> But the tcpdump process runs continuously.  Only stopped by outside
> forces and then restarted.
> 
> There is probably some standard way to put those pid numbers in
> /var/run but I don't know it.

use File::Basename;

my $pid_file = '/var/run/' . basename( $0 ) . '.pid';
{ open my $PID, '>', $pid_file and print $PID "$pid\n" };



John
-- 
use Perl;
program
fulfillment

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




Re: remove '\' with new-line

2004-03-02 Thread John W. Krahn
Jeff Westman wrote:
> 
> I need a one-liner to convert all occurances read from a Unix pipe
> of
> 
>   'backslash' + 'literal new line (hex 0a)'
> 
> to become just
> 
>   'literal new line (hex 0a)'
> 
> That is, remove the '\' only when it preceeds a new-line.  Again,
> this must be read from a pipe.  This is what I have so far, but it
> doesnt do work:
> 
>   cat dfile | perl -pe 'BEGIN { $str = ord(10); } s!\\$str!$str!g'
> 
> Suggestions?!


cat dfile | perl -pe's/\\$//'

Or just:

perl -pe's/\\$//' dfile



John
-- 
use Perl;
program
fulfillment

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




Re: listing prime numbers in a range (Beginning Perl exercise)

2004-03-02 Thread Stuart White

> 
> Stuart, can we please see the whole script?
> 

#!/usr/bin/perl
# primeNumbers.pl
use warnings;
use strict;
my $input;
my @list;
my @primelist;
my @newPrimeList;
my $i;
my $j;
print "I want you to enter a list of numbers bigger
than 2.\n";
print "To mark the end of your list, enter 0.\n";
print "Enter a number that is bigger than 2:\t";
$input = ;
chomp($input);
print "This is your number: $input \n";
@list = (2 .. $input);

print "this is this the fourth element, but has an
index of 3: $list[3]\n";
#this foreach loop goes through the @list array,
putting the odd
#numbers into a new array, @primelist

foreach (@list)
{ 
 if ($_ % 2 != 0)
 {
  unshift(@primelist, $_);
print "this is the inner loop of primelist:
@primelist\n";  
 }
}
print "this is the outer loop of primelist:
@primelist\n";  

#for loops that will loop through @list and
@primelist, getting the
#modulus of @primelist.  I anticipate that this will
isolate prime
#numbers.
 for ($i = 0; $i <= $input; $i++)
 {
  for ($j = 0; $j <= $input; $j++)
{
   if ($primelist[$i] % $list[$j])
 {
  unshift(@newPrimeList, $primelist[$i]);
print "I just added $primelist[$i] to
newPrimeList.\n";
 } 
}
 }  
 print "this is primelist:  @primelist\n";
 print "this is newPrimeList:  @newPrimeList\n";
  

> James
> 


__
Do you Yahoo!?
Yahoo! Search - Find what you’re looking for faster
http://search.yahoo.com

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




Seek on Unix JFS file systems

2004-03-02 Thread Ashley Cooper
Hi All,

I have an issue with a Perl script designed to count pages in a TIFF file on AIX.

The result I get depends on the location of the TIFF file when I count it.  
Specifically, when the TIFF file resides on a "JFS2" file system or a "JFS" file 
system which has large file support (> 2Gb) enabled, the seek works, otherwise the 
seek fails.  Obviously this impacts on the correctness of the page count reported.

Code snippet and sample output follows:

-
## open the file for reading.
open (FIN, $_[0]) || die "couldn't open the file! $_[0]";

## read the 8 header bytes (3 fields), and unpack the mode
## to determine byte order (endian)
read FIN, $record, 8;
($mode) = unpack "A2", $record;

if ($mode eq "MM") {# big endian
$header_template = "A2nN";
$idf_tag_template = "n";
$next_offset_template = "N";

} elsif ( $mode eq "II" ) { # little endian
$header_template = "A2SL";
$idf_tag_template = "S";
$next_offset_template = "L";
} else {
die "invalid file format or not a TIFF file ($_[0])";
}

## unpack the header
($mode, $magic, $offset) = unpack $header_template, $record;
print "\n(1) mode:$mode, magic:$magic, offset:$offset\n";

## count the pages (images)
while ( $offset ) {

$page_count++;

## Move the file pointer to the beginning of the first IDF,
## read the number of entries in the IDF, and unpack the number
print "\nSeek to IDF at offset $offset\n";
my $seek_ok = seek(FIN, $offset, 0);

if ($seek_ok == 0) {
   print "Seek for IDF failed: $!\n";
} else {
   print "Seek OK!\n";
}
 ...
 
 ...
   }

--
Sample output from *NON* JFS file system:

(1) mode:II, magic:10752, offset:3556769792
Seek to IDF at offset 3556769792
Seek for IDF failed: A system call received a parameter that is not valid.

--
Sample output from JFS file system:

(1) mode:II, magic:10752, offset:3556769792
Seek to IDF at offset 3556769792
Seek OK!



I have tried using binmode() but that makes no difference.  Has anyone else 
encountered anything like this?  If so, how did you resolve it?

Regards,
Ashley


*
This e-mail, including any attachments to it, may contain confidential and/or personal 
information.
If you have received this e-mail in error, you must not copy, distribute, or disclose 
it, use or take any action 
based on the information contained within it.

Please notify the sender immediately by return e-mail of the error and then delete the 
original e-mail.

The information contained within this e-mail may be solely the opinion of the sender 
and may not necessarily 
reflect the position, beliefs or opinions of Salmat on any issue.

This email has been swept for the presence of computer viruses known to Salmat's 
anti-virus systems.

For more information, visit our website at  www.salmat.com.au.
*


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




Re: print a 3D array

2004-03-02 Thread R. Joseph Newton
"R. Joseph Newton" wrote:

> ARRAY<0x22bdfb0>
> not
> ARRAY(0x22bdfb0)
> although the two are almost undistinguishable in the default font used by
> cmd.exe.

Whoopsy.  Guess its time to change my default font.

Sorry

Joseph


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




Re: How to capture pid

2004-03-02 Thread Harry Putnam
"John W. Krahn" <[EMAIL PROTECTED]> writes:

> open FILE, '>file' or die "Cannot open file: $!";
> my $pid = open DUMP, 'tcpdump -v -ieth0 |' or die "Cannot open pipe from
> tcpdump: $!";
> print FILE while ;
> close DUMP or die "Cannot close pipe from tcpdump: $!";
> close FILE;
>
> print "Pid was $pid\n";

Looking at this, I'm guessing one doesn't get to know the pid until
its all over.  (I can't try it out right now).  Which in this case
would not be usefull.

This thing needs to run until at the 4hr mark syslog sends a SIGHUP
and rotates the ouput files.  All that is taken care of by syslog.

But the tcpdump process runs continuously.  Only stopped by outside
forces and then restarted.

There is probably some standard way to put those pid numbers in
/var/run but I don't know it.  

I thought perl could do it fairly easily but maybe not.

I can always grep the ps output inside the script and get it that way.

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




RE: Only reading even lines in file -skipping odd ones!

2004-03-02 Thread Mark Anderson

> i am trying to write a perl script to tidy up any lines in a file that
don't
> contain alphabetic characters or single instances of character. i've
noticed
> that the even lines are being skipped when read in eg 0,2,4,6 - the script
> is run on window - any ideas?

> while () {

This line reads the first (and other odd lines of INPUT) and places the
contents into $_

>  chomp($test=);

This line reads the second (and other even lines of INPUT) and places the
contents into $test

The following lines print $test to OUTPUT 1 regardless of what is in it

> if ( $test =~/\w/)

> {print OUTPUT1 "$test\n"}

> if ( $test !~/[A-Za-z]/)

> {print OUTPUT1 "$test\n"}

> else

> {print OUTPUT "$test\n"}

The contents of $_ are overwritten on the next call of the while line.

Hope this helps,
/\/\ark



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




Re: Only reading even lines in file -skipping odd ones!

2004-03-02 Thread david
Stephen Kelly wrote:

> hi there
> 
> i am trying to write a perl script to tidy up any lines in a file that
> don't contain alphabetic characters or single instances of character. i've
> noticed that the even lines are being skipped when read in eg 0,2,4,6 -
> the script is run on window - any ideas?
> 
> # Tidy Glossaries
> 
> #!/usr/bin/perl -w
> 

when you are starting to learn Perl, you should try:

use strict;

in your script.

> open INPUT, "d:/projects/perlscripts/oc_jp.txt"
> or die "Can't open d:/projects/perlscripts/oc_jp.txt for reading
> $!\n";
> open OUTPUT, ">>d:/projects/perlscripts/oc_jp_tidy.txt"
> or die "Can't open d:/projects/perlscripts/oc_jp_tidy.txt $!\n";
> open OUTPUT1, ">>d:/projects/perlscripts/oc_jp_untidy.txt"
> or die "Can't open d:/projects/perlscripts/oc_jp_untidy.txt $!\n";

you should declare a few variables to hold the name of the files:

my $input = 'd:/projects/perlscripts/oc_jp.txt';
my $tidy  = 'd:/projects/perlscripts/oc_jp_tidy.txt';
my $mess  = 'd:/projects/perlscripts/oc_jp_untidy.txt';

you can then open them accordingly:

open INPUT, $input or die "Can't open $input: $!\n";
open TIDY,  ">>$tidy"  or die "Can't create $tidy: $!\n";
open MESS,  ">>$mess"  or die "Can't create $mess: $!\n";

notice this improve readability and consequencely maintainability.

> 
> 
> while ()
> {
> 

you got a line from the input file and store it in $_ but you never use $_ 
in your script which means the line is discarded

>
>  chomp($test=);
>

you read another line from the input file and assigne it to $test. at time 
point, you have already read 2 lines. this is most likely the reason why 
you are seeing "even lines". each loop iteration, you read 2 lines.

david
-- 
s$s*$+/http://learn.perl.org/> 




Re: Inserting chr(27) at the beggining of a text file

2004-03-02 Thread Rob Dixon
Steve Hemond wrote:
>
> I need to insert the ESC character followed by a couple of other
> characters at the beginning of a text file without overwriting it. What
> is the best way to do it?

Hi Steve.

When you say 'without overwriting it' do you mean that you want to keep a
backup copy or that you don't want to rewrite the entire file? If it's the
latter then you're out of luck, but don't decide that it's going to be too
slow without trying it.

Tie::File may be your best bet here. It lets you edit text lines from your file
by just changing the array elements. The change is made straight away and the
module is intelligent about buffering and doesn't read or write any more than
it needs to.

You can best express the escape sequence you want to add with "\e" followed by
the exact sequence. For instance, "\e[2J" is ANSI clear-screen.

Take a look at this program. I hope it helps.

Rob



  use strict;
  use warnings;

  use Tie::File;

  tie my @file, 'Tie::File', 'file.txt';

  $file[0] = "\e[2J".$file[0];

  untie @file;



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




Threads in Perl

2004-03-02 Thread Tim Johnson

Can anyone give me a quick hint as to where to find documentation on how
to use threads w/Perl?  

I understand that it's one of the main differences between 5.8.x and
5.6.x, but I'm having trouble finding docs on it.  I get back way too
many irrelevant results when I google, etc.


Re: remove '\' with new-line

2004-03-02 Thread david
Jeff Westman wrote:

> I need a one-liner to convert all occurances read from a Unix pipe
> of
> 
>   'backslash' + 'literal new line (hex 0a)'
> 
> to become just
> 
>   'literal new line (hex 0a)'
> 
> That is, remove the '\' only when it preceeds a new-line.  Again,
> this must be read from a pipe.  This is what I have so far, but it
> doesnt do work:
> 
>   cat dfile | perl -pe 'BEGIN { $str = ord(10); } s!\\$str!$str!g'
> 
> Suggestions?!

that's because:

[panda]# perl -le 'print ord(10)'
49
[panda]# perl -e 'print chr(10)'

[panda]#

you want chr(10):

[panda]# cat dfile
\abcd\xxx\yyy\
1234\zzz

[panda]# perl -pe 's.\\\n.\n.g' < dfile
\abcd\xxx\yyy
1234\zzz

[panda]# perl -pe 'BEGIN{$n = chr(10)} s.\\$n.$n.g'
\abcd\xxx\yyy
1234\zzz

david
-- 
s$s*$+/http://learn.perl.org/> 




Re: OO Programming

2004-03-02 Thread WilliamGunther
In a message dated 3/2/2004 7:57:45 PM Eastern Standard Time, 
[EMAIL PROTECTED] writes:
>Is there any good documentation for in OO PERL Programming?

Yep. In no particular order:

 perldoc perlref
 perldoc perlboot
 perldoc perltoot
 perldoc perltooc
 perldoc perlbot
 perldoc perlobj
 perldoc perlreftut

IMHO, Object Oriented Perl is the best book you can get on the subject.

-will
(the above message is double rot13 encoded for security reasons)

Most Useful Perl Modules
-strict
-warnings
-Devel::DProf
-Benchmark
-B::Deparse
-Data::Dumper
-Clone (a Godsend)
-Perl::Tidy
-Beautifier


Only reading even lines in file -skipping odd ones!

2004-03-02 Thread stephen kelly
hi there

i am trying to write a perl script to tidy up any lines in a file that don't
contain alphabetic characters or single instances of character. i've noticed
that the even lines are being skipped when read in eg 0,2,4,6 - the script
is run on window - any ideas?

# Tidy Glossaries

#!/usr/bin/perl -w

open INPUT, "d:/projects/perlscripts/oc_jp.txt"
or die "Can't open d:/projects/perlscripts/oc_jp.txt for reading $!\n";
open OUTPUT, ">>d:/projects/perlscripts/oc_jp_tidy.txt"
or die "Can't open d:/projects/perlscripts/oc_jp_tidy.txt $!\n";
open OUTPUT1, ">>d:/projects/perlscripts/oc_jp_untidy.txt"
or die "Can't open d:/projects/perlscripts/oc_jp_untidy.txt $!\n";


while ()
{

 chomp($test=);

 if ( $test =~/\w/)

 {print OUTPUT1 "$test\n"}

 if ( $test !~/[A-Za-z]/)

 {print OUTPUT1 "$test\n"}

 else

 {print OUTPUT "$test\n"}




}

close INPUT;
close OUTPUT;
close OUTPUT1;



here is 3 lines of the source file

The IDM item is not available. Das IDM-Objekt ist nicht verfügbar.
{0} {0}
Document is offline. Dokument ist offline.
Insufficient privilege. Unzureichende Rechte.



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




Re:OO Programming

2004-03-02 Thread Wyndell
Is there any good documentation for in OO PERL Programming?



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




Re: Why did it print a happy face?

2004-03-02 Thread Rob Dixon
Joel wrote:
>
> This is a precursor to a real JAPH signeture (I need to learn more perl
> before I can write a really obfuscated one), and I have already gotten it to
> print what it was supposed to, but I changed print chr($letter); to print
> chr(@word); to see if it would work, which is when I got the happy face
> output in perl. Any ideas?
> (By the way, I haven't fixed the while loop yet so be ready to quit fast to
> read the output.)
>
> Joel
>
> #!usr/bin/perl
>
> use Warnings;
> use Strict;
>
> my $h=4;
> my @word = (0x4E, 0x65, 0x72, 0x64);
> while ($h > 0) {
>  $h++;
>  $letter=shift @word;
>  print chr(@word);
> }

Hmm. I'm don't think I should be encouraging anybody to write obfuscated
Perl. Almost nobody does it well - including me.

Why are you /incrementing/ $h from four until it's greater than zero?

Your bug is that chr() forces its parameter into scalar mode, so that your
output will be

  "\03\02\01\0\0\0\0\0\0"

Although your capitalised pragma could almost be seen as divisive: there's
neither a 'Warnings' nor a 'Strict', so you're practising unprotected
unintentional obfuscation.

Write Perl well first. Please. Then write somthing clever.

Rob



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




Re: Checking filenames?

2004-03-02 Thread Jas
No, your right, it does drop the zero.  I am going to test your solution 
to the problem. Seeing as I should be the one claiming insanity on not 
learning perl earlier.  =)
Jas

Wc -Sx- Jones wrote:
Jenda?

This is the partial original post -

Jas wrote:

Wouldn't this be better?

my $year = "";
my $month = "";
my $day = "";
if($file =~ /^(\d{4})(\d{2})(\d{2})-www.tar.gz$/) {
  $year = $1;
  $month = $2;
  $day = $3;
my $chk = "$month - 1";


Here - this is weird =)

"03" in numerical context is 3.

File name was 20040301 - collapses to 200431 -
Not a match IMHO.
foreach($file ! $chk) {
  $ftp->delete($file); }
??? Not sure but I am going to test it out


Maybe I am totally confused - I have been working on WebSphere.  Yes, I 
plead complete insanity.

-Bill-
__Sx__
http://youve-reached-the.endoftheinternet.org/


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



Re: Inserting strings into a file

2004-03-02 Thread Peter Scott
In article <[EMAIL PROTECTED]>,
 [EMAIL PROTECTED] (Steve Hemond) writes:
>Hi again,
>As you can see, I wasn't able to build the string like this :
>printf FILE "\e%-12345X @PJL JOB NAME = $ARGV[1] \n";
>
>Because between double quotes the @ of @PJL will be interpolated, which
>I don't want.

Just backslash it:

printf FILE "\e%-12345X [EMAIL PROTECTED] JOB NAME = $ARGV[1] \n";

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

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




Re: How to capture pid

2004-03-02 Thread John W. Krahn
Harry Putnam wrote:
> 
> What is the handy way to record the pid of $some_process in this
> fake code?
> 
> $some_process = 'tcpdump -v -ieth0 >file')
> system("$some_process") or die "Can't start $some_process: $!";

system() returns false on success and true on failure so "or die ..."
will execute when system() succeeds and the $! variable does not contain
any useful information, you need $? instead.

perldoc -f system

> print "Pid is $pid\n";
> 
> The process is started by a more elaborate perl script at bootup.
> and restarted every four hours from syslog. Code above is way simplified.

open FILE, '>file' or die "Cannot open file: $!";
my $pid = open DUMP, 'tcpdump -v -ieth0 |' or die "Cannot open pipe from
tcpdump: $!";
print FILE while ;
close DUMP or die "Cannot close pipe from tcpdump: $!";
close FILE;

print "Pid was $pid\n";

__END__



John
-- 
use Perl;
program
fulfillment

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




Re: How to capture pid

2004-03-02 Thread Harry Putnam
"Hanson, Rob" <[EMAIL PROTECTED]> writes:

> I'm not sure, probably by forking and execing.  It won't return the result
> code from the other program though.
>
>
> $some_process = 'tcpdump -v -ieth0 >file';
>
> my $pid = fork();
> unless ($pid) {
>   exec($some_process);
>   die "Can't start $some_process: $!";
> }
>
> print "Pid is $pid\n";
>

For some reason the pid printed does not match the output of ps:

actual sample script"
---
#!/usr/local/bin/perl -w

my $cmd   = 'tcpdump -v -ttt -i rl0 -w ';
my $fpath  = "/var/log/dump";
my $base_fname  = "dump_all";
my ($afname);
$afname = "$fpath" . "/" . "$base_fname";

my $pid = fork();
unless ($pid) {
  exec("$cmd $afname &");
  die "Can't start $cmd: $!";
}

print "Pid is $pid\n";
---
Script output:
   # dump_all.pl
  Pid is 15173
  [fwobsd:root] /root
   # tcpdump: listening on rl0
  ps wwaux|grep tcpdump
  root 30335  0.0  1.6  1116  1048 p0  S  6:03PM0:00.02
  tcpdump -v -ttt -i rl0 -w /var/log/dump/dump_all (tcpdump-3.4.0-or)

Note the script outputs 15173 and ps shows 30335

Do you have an idea what is happening here? 

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




Re: Reading File & grep according item 5 and sorting

2004-03-02 Thread John W. Krahn
Bjorn Van Blanckenberg wrote:
> 
> On 28-feb-04, at 20:32, R. Joseph Newton wrote:
> 
> > Bjorn Van Blanckenberg wrote:
> >
> >> let say that the file contains these items (every item is seperated
> >> with a tab)
> >>
> >> one  title3   state3   name3   pre   number3
> >> dip  title6   state6   name6   pre2   number6
> >
> > So what changes have you made in the code to reflect this diffeence in
> > specification.  Let us know how *your* adaptations work.
> 
> #!/usr/bin/perl
> 
> use strict;
> use Getopt::Long;
> 
> GetOptions(\my %opt, 'filepath=s');
> 
> my $filepath = (%opt->{'filepath'});

That is not how you access a hash value.  There is nothing to
dereference as %opt is a hash, not a reference to a hash and a hash
value is a scalar so it should start with '$' not '%'.

my $filepath = $opt{filepath};


> my @fields = ();
> my @sorted = ();
> my $lastbit = 1;
> my @bits = ();

For the array declarations the ' = ()' is redundant as my() creates
arrays with that value by default.


> open(INFILE,$filepath);

You should *ALWAYS* verify that the file was opened successfully.

open INFILE, $opt{filepath} or die "Cannot open $opt{filepath}: $!";


> chomp(@fields = );
> 
> @sorted =
> map { $_->[0] }
> sort { $a->[5] cmp $b->[5] }
> map { [ $_ , (split /\t/) ] } @fields;
> 
> foreach (@sorted){
> @bits = split;
> print "\n" if ($bits[4] ne $lastbit);

Your problem is that all the values in $bits[4] are different so that
will always print a newline.

> print "$_\n";
> $lastbit=$bits[4];
> }


John
-- 
use Perl;
program
fulfillment

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




Re: Why did it print a happy face?

2004-03-02 Thread Rob Dixon
Joel wrote:
>
> Thanks for explaining the while loop, but what I was wondering is why perl
> printed the happy face and heart in the first place? I was using ASCII
> Characters and there aren't any like that.

But you weren't using ASCII characters unless your terminal saw them as such.
You were using byte values.

Tell us what platform you're on. It sounds a lot like DEC (Compaq) to me.

Rob



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




remove '\' with new-line

2004-03-02 Thread Jeff Westman
I need a one-liner to convert all occurances read from a Unix pipe
of 

  'backslash' + 'literal new line (hex 0a)'

to become just

  'literal new line (hex 0a)'

That is, remove the '\' only when it preceeds a new-line.  Again,
this must be read from a pipe.  This is what I have so far, but it
doesnt do work:

  cat dfile | perl -pe 'BEGIN { $str = ord(10); } s!\\$str!$str!g'

Suggestions?!

__
Do you Yahoo!?
Yahoo! Search - Find what you’re looking for faster
http://search.yahoo.com

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




RE: listing prime numbers in a range (Beginning Perl exercise)

2004-03-02 Thread Stuart White

--- David le Blanc
<[EMAIL PROTECTED]> wrote:
> 
> Just for the sake of it, and I apologise profusely
> for the top posting..
> 
stuart>Hi David,


> Here is a summary of the posted prime calculators
> for testing your
> results against.
> 
> >(1) Ohad

stuart>I saw his regexp soln.  I was attempting to
stuart>solve it with arrays, loops and maybe hashes. 
stuart>I figure that the exercise wouldn't be in the
stuart>book before the regexp chapter if I couldn't do
stuart>it easily (or without TOO much difficulty)
stuart>without them.  That's all.

> >(2) Joseph
stuart>I thought this one was a joke.  Partly because
stuart>of the context it was sent in, partly because
stuart>of what I saw it do.  I ran it, and it printed
stuart>out a slew of numbers.  It didn't stop after a
stuart>few minutes, so I ended the program.


> >(3) me (Hey, it's a Mee Too!)
>
#---
> $max=shift||17393;
> %notprime=();
> @prime=();
> 
> for $n (2..$max){
>   unless($notprime{$n}){
>   push @prime,$n;
>   $notprime{$_*$n}=1 for 2..$max/$n;
>   }
> }
> 
> print "Found $#prime prime numbers..".$/;
> print "@prime\n";
>
#---
> 
> Brief explanation..
> (1) 
sounds neat.
 
> (2) Joseph posted a calculator which uses the
> feature of prime numbers
> that the 
> largest number you need to divide it by is the
> square root of itself
> ($_**0.5)
> and that you only need to test if the number you
> are examining is
> divisible
> (ie mod==0) by another prime you have already
> found.  Hence, very
> quick and
> very cpu/memory cheap.  Why not test against
> every number?  If you
> test against
> a non-prime number, you are simply testing
> against a multiple of a
> prime of
> course.

stuart>Ahh, this makes sense, sortof.  I'm going to
stuart>need to look at the code again and your
stuart>explanation.  This was printing many, many,
stuart>many numbers, some of which sure didn't look
stuart>like they were primes.  The sheer number plus
stuart>the proximity of them to each other in
stuart>cardinal? order (2341  2347 2443 etc) (these
stuart>numbers are used to illustrate my probably
stuart>improper use of cardinal, I'm not implying that
stuart>those numbers were outputted by the program)
stuart>made me think that some weren't primes.


> 
> (3) A very simple implementation of an erogenous
> sieve (iud? did I say
> that wrong?)
> which keeps all primes in '@primes' and all
> 'eliminated' entries in
> '%notprime'.
> quick, but likely more memory intensive than
> (2).

This one is a bit confusing. 
$max=shift||17393;
stuart>I thought shift was to remove an element from
stuart>the beginning of an array, but it's being used
stuart>in scalar context here.  Why?  And what is it
stuart>doing?

 %notprime=();
> @prime=();
> 
> for $n (2..$max){
stuart>this makes me think that you were somehow
stuart>assigning a number to $max above.  But where
stuart>does 17393 come in?  Why not 17394, or 18000?


>   unless($notprime{$n}){
>   push @prime,$n;
>   $notprime{$_*$n}=1 for 2..$max/$n;
stuart>I'm not sure I understand this line directly
stuart>above.  What I think it says is that it is
stuart>accessing the value within the %notprime hash
stuart>where the key equals the last inputted number
stuart>which I suppose is $n and $_ if $n was pushed
stuart>onto @prime, but just $_ if $n was not pushed
stuart>onto @prime.  I don't get the "=1" part
stuart>though.  What is that doing?  I'm assuming that
stuart>is a for loop there that is working like a
stuart>foreach loop?  but I'm not quite sure what it's
stuart>doing.

> Cheers.
> David
> 
>

__
Do you Yahoo!?
Yahoo! Search - Find what you’re looking for faster
http://search.yahoo.com

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




Re: Inserting strings into a file

2004-03-02 Thread John W. Krahn
Steve Hemond wrote:
> 
> Hi again,

Bonjour,

> As you know, I am trying to insert a string at the beginning of a file
> without overwriting its contents. Since my file is an HP/GL2 output
> file, I put every hp/gl2 command and stack them into an array. I then
> truncate the file, insert my specific string, and then put back all the
> commands after that string :
> 
> open (FILE, "+>>$ARGV[0]") or die ("Can`t open file! : $!\n");
   ^^^
You should use '+<' instead of '+>>'.

> # We put contents of the file in a temporary scalar
> my $in = ;

You are assigning the first record of the file to $in, not the entire
contents.

> # Clear the file
> truncate (FILE,0) or die ("Can't truncate file! : $! \n");

You don't really need to truncate the file because the new file will be
longer then the old file.

> # Build the string to insert at the beginning
> my $jobname = $ARGV[1]; #ARGV[0] is the file to be modified
> my $pjl = '@PJL JOB NAME = "' . $jobname . '"' . '\n'; # What a dumb way
> to build the string, any better ideas?
> printf FILE "\e%-12345X ";

printf() uses the '%' character to indicate the start of a format
string, in this case '%-12345X' which will print a 12,345 long string. 
Is that what you want?  Or did you mean to use print() instead?

> print $pjl;

Before you can print to the file, you have to seek() to the beginning of
the file or it will not work properly.

> As you can see, I wasn't able to build the string like this :
> printf FILE "\e%-12345X @PJL JOB NAME = $ARGV[1] \n";
> 
> Because between double quotes the @ of @PJL will be interpolated, which
> I don't want.

Just put a backslash in front of it: "\e%-12345X [EMAIL PROTECTED] JOB NAME =
$ARGV[1] \n"

> When running the script I get this error :
> Use of uninitialized value in printf at ./hptable.pl line 126, 
> line 1.
> line 126 = printf FILE "\e%-12345X ";

"uninitialized value" implies that there is a variable with the value
undef being printed.

$ perl -le'use warnings; use strict; my $x; printf "abcd  %-12X\n", $x;'
Use of uninitialized value in printf at -e line 1.
abcd  0   

But you don't have any variables on that line.



John
-- 
use Perl;
program
fulfillment

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




Re: How to capture pid

2004-03-02 Thread John McKown
On Tue, 2 Mar 2004, Harry Putnam wrote:

> 
> What is the handy way to record the pid of $some_process in this
> fake code?
> 
> $some_process = 'tcpdump -v -ieth0 >file')
> system("$some_process") or die "Can't start $some_process: $!";
> 
> print "Pid is $pid\n";
> 
> The process is started by a more elaborate perl script at bootup.
> and restarted every four hours from syslog. Code above is way simplified.
> 
> 

I don't think you can get the PID when using the system() function. Also, 
I am fairly sure that system() does not return control to your Perl script 
until the function it invokes finishes. Would something like:

use Errno qw(EAGIN);
...
$someprocess=...
FORK: {
if ($pid=fork) {
print "PID is $pid\n";
}
elsif (defined $pid) {
exec $someprocess;
}
elsif ($!=EAGIN) {
sleep 5; #wait five seconds
redo FORK; #then try again
}
else {
die "Cannot fork to run $someprocess $!";
}
}

--
Maranatha!
John McKown


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




interacting with table layouts using DBI

2004-03-02 Thread Andrew Gaffney
Is there an easy way with DBI (or anything other modules) to retrieve and modify the 
layout of database tables in a MySQL DB? I need to write a program to add 2 fields to ~40 
tables with an identical layout. The tables are named "m"mmyy where "m" is an actual 'm', 
mm is a 2 digit month, and  is a 4 digit year. If the table doesn't exist, I want to 
create it with the same layout as all the rest. I can write a program that does this the 
hard way, but before I started, I wanted to know if there was an easier way.

--
Andrew Gaffney
Network Administrator
Skyline Aeronautics, LLC.
636-357-1548
--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
 



Re: Inserting strings into a file

2004-03-02 Thread Rob Dixon
Steve Hemond wrote:
>
> As you know, I am trying to insert a string at the beginning of a file
> without overwriting its contents. Since my file is an HP/GL2 output
> file, I put every hp/gl2 command and stack them into an array. I then
> truncate the file, insert my specific string, and then put back all the
> commands after that string :
>
> open (FILE, "+>>$ARGV[0]") or die ("Can`t open file! : $!\n");

Why is the end of your current file a safer place to write than a separate,
new file? If you explained then I'm sure we could find an easier way. I've
never seen code that needed to be written like this. Are you just looking
for something that needs to be atomic? (Without a separate process being
able to see anything but the 'before' or the 'after')?

> # We put contents of the file in a temporary scalar
> my $in = ;
>
> # Clear the file
> truncate (FILE,0) or die ("Can't truncate file! : $! \n");

Without any locking, this file could have been read by a separate process
either before, after, or even (if you're unlucky with your filing system)
half-way through the truncation. Writing code this way will only confuse
your solution and won't protect in any way.

Two of us, including me, asked exactly what you meant by, 'without
overwriting its contents'. Why won't you tell us?

> # Build the string to insert at the beginning
> my $jobname = $ARGV[1]; #ARGV[0] is the file to be modified
> my $pjl = '@PJL JOB NAME = "' . $jobname . '"' . '\n'; # What a dumb way to
> build the string, any better ideas?

  my $pjl = "\e%-12345X [EMAIL PROTECTED] JOB NAME = \"$jobname\"\n";

> printf FILE "\e%-12345X ";
> print $pjl;

You see, here you are, 'overwriting' the file, which you said you mustn't
do.

> As you can see, I wasn't able to build the string like this :
> printf FILE "\e%-12345X @PJL JOB NAME = $ARGV[1] \n";
>
> Because between double quotes the @ of @PJL will be interpolated, which
> I don't want.
>
> When running the script I get this error :
> Use of uninitialized value in printf at ./hptable.pl line 126, 
> line 1.
> line 126 = printf FILE "\e%-12345X ";

I can't spot any problem, but you need 'print' instead of 'printf' here. I
suspect the real source code is different from what you've shown. My Perl
runs this single line fine.

> I'd like first to know a better way to build the string (avoiding the @
> interpolation).

My above (again):

  my $pjl = "\e%-12345X [EMAIL PROTECTED] JOB NAME = \"$jobname\"\n";

is the nicest way I can think of. Single quotes will let you use '@' and '%' literally,
but also prevent you from interpolating the scalar $jobname and using "\e" and "\n".

> Then I'd like to know why I get that error when printing the string in
> the file.

Not yet, but I HTH in some way.

Rob



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




RE: How to capture pid

2004-03-02 Thread Hanson, Rob
I'm not sure, probably by forking and execing.  It won't return the result
code from the other program though.


$some_process = 'tcpdump -v -ieth0 >file';

my $pid = fork();
unless ($pid) {
  exec($some_process);
  die "Can't start $some_process: $!";
}

print "Pid is $pid\n";


-Original Message-
From: Harry Putnam [mailto:[EMAIL PROTECTED]
Sent: Tuesday, March 02, 2004 3:34 PM
To: [EMAIL PROTECTED]
Subject: How to capture pid



What is the handy way to record the pid of $some_process in this
fake code?

$some_process = 'tcpdump -v -ieth0 >file')
system("$some_process") or die "Can't start $some_process: $!";

print "Pid is $pid\n";

The process is started by a more elaborate perl script at bootup.
and restarted every four hours from syslog. Code above is way simplified.

-- 
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: listing prime numbers in a range (Beginning Perl exercise)

2004-03-02 Thread Stuart White

--- James Edward Gray II <[EMAIL PROTECTED]>
wrote:
 
> It makes perfect sense, yes, but I'm still missing
> one piece of 
> information, the broken code you would like fixed. 
> As I said in my 
> last message, "...just post that nested foreach and
> let us help you fix 
> it."

My mistake, I thought I had pasted into my message.
Here it is:
===
#for loops that will loop through @list and
@primelist, getting the
#modulus of @primelist.  I anticipate that this will
isolate prime
#numbers.
 for ($i = 0; $i <= $input; $i++)
 {
  for ($j = 0; $j <= $input; $j++)
{
   if ($primelist[$i] % $list[$j])
 {
  unshift(@newPrimeList, $primelist[$i]);
print "I just added $primelist[$i] to
newPrimeList.\n";
 } 
}
 }  
 print "this is primelist:  @primelist\n";
 print "this is newPrimeList:  @newPrimeList\n";


__
Do you Yahoo!?
Yahoo! Search - Find what you’re looking for faster
http://search.yahoo.com

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




Re: Ternary operator question

2004-03-02 Thread WilliamGunther
In a message dated 3/2/2004 9:21:57 AM Eastern Standard Time, 
[EMAIL PROTECTED] writes:
>$#array + 1 still is the size of the array and it won't modify the 
>array.  That's not what we were talking about.  We were talking about 
>++$#array, which expands to $#array = $#array + 1.  Note the equal sign 
>there, because it's what modifies the array.

$#array + 1 is the length99% of the time. Until you modify $[, in which case 
the size is $#array - $[ + 1. But, don't modify $[ (unless you want to :-) )

-will
(the above message is double rot13 encoded for security reasons)

Most Useful Perl Modules
-strict
-warnings
-Devel::DProf
-Benchmark
-B::Deparse
-Data::Dumper
-Clone (a Godsend)
-Perl::Tidy
-Beautifier

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




Re: ENV variables and custom 404 error page

2004-03-02 Thread Bryan Harris


> Bryan Harris wrote:
>>> # do this. make sure that this line is the
>>> # ONLY thing you print out to the browser.
>>> print "Location: http://rightplace.com/\n\n";;
>> 
>> 
>> Wow, this is cool!  Where is this documented?  I'm interested in
>> learning about other things like this...
> 
> This is part of the HTTP spec, which is defined in RFC 2616:
> 
> http://www.w3.org/Protocols/rfc2616/rfc2616-sec14.html#sec14.30
> 
> The CGI module can produce a redirect header as well, with its redirect()
> method.


Thanks, Bill and Bob, I'll look into all of them...

- B


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




How to capture pid

2004-03-02 Thread Harry Putnam

What is the handy way to record the pid of $some_process in this
fake code?

$some_process = 'tcpdump -v -ieth0 >file')
system("$some_process") or die "Can't start $some_process: $!";

print "Pid is $pid\n";

The process is started by a more elaborate perl script at bootup.
and restarted every four hours from syslog. Code above is way simplified.

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




RE: Why did it print a happy face?

2004-03-02 Thread Paul Kraus
Yes there are. The extended ASCII set. Do a search of google extended ASCII
chart.

 Paul Kraus
 ---
 PEL Supply Company
 Network Administrator

> -Original Message-
> From: Joel [mailto:[EMAIL PROTECTED]
> Sent: Tuesday, March 02, 2004 1:25 PM
> To: Shaw, Matthew
> Cc: perl
> Subject: Re: Why did it print a happy face?
> 
> Thanks for explaining the while loop, but what I was wondering is why perl
> printed the happy face and heart in the first place? I was using ASCII
> Characters and there aren't any like that.
> 
> Thanks
> 
> Joel
> 
> - Original Message -
> From: "Shaw, Matthew" <[EMAIL PROTECTED]>
> To: "Joel" <[EMAIL PROTECTED]>
> Sent: Tuesday, March 02, 2004 12:13 PM
> Subject: RE: Why did it print a happy face?
> 
> 
> Joel:
> 
> There's a few problems with your sample code... please see my comments
> below:
> 
> #!usr/bin/perl # You forgot the leading slash in your path here
> 
> use Warnings; # This should be 'use warnings;' (Lowercase)
> use Strict; # This should be 'use strict;' (Lowercase)
> 
> my $h=4;
> my @word = (0x4E, 0x65, 0x72, 0x64);
> while ($h > 0) {
>  $h++; # This should probably be $h-- if you want your while loop to end
>  $letter=shift @word;
>  print chr(@word); # chr() is evaluating the @word array in scalar
> context,
> # which returns the number of elements in the
> array.
> # this line is printing the characters 4, 3, 2,
> 1 (As you
> # shift off the array) and finally '0' over and
> over
> # again when the array contains no elements.
> }
> 
> # end
> 
> Here's another way of writing what (I think) you intended:
> 
> #!/usr/bin/perl
> 
> use warnings;
> use strict;
> 
> my @word = (0x4E, 0x65, 0x72, 0x64);
> print chr for @word;
> 
> # end
> 
> Hope this helps. Enjoy and let me know if you have any questions.
> 
> Thanks
> 
> Matt Shaw
> Technical Architect
> xwave, An Aliant Company
> Desk: 506-389-4641
> Cell: 506-863-8949
> [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: Why did it print a happy face?

2004-03-02 Thread Joel
Thanks for explaining the while loop, but what I was wondering is why perl
printed the happy face and heart in the first place? I was using ASCII
Characters and there aren't any like that.

Thanks

Joel

- Original Message - 
From: "Shaw, Matthew" <[EMAIL PROTECTED]>
To: "Joel" <[EMAIL PROTECTED]>
Sent: Tuesday, March 02, 2004 12:13 PM
Subject: RE: Why did it print a happy face?


Joel:

There's a few problems with your sample code... please see my comments
below:

#!usr/bin/perl # You forgot the leading slash in your path here

use Warnings; # This should be 'use warnings;' (Lowercase)
use Strict; # This should be 'use strict;' (Lowercase)

my $h=4;
my @word = (0x4E, 0x65, 0x72, 0x64);
while ($h > 0) {
 $h++; # This should probably be $h-- if you want your while loop to end
 $letter=shift @word;
 print chr(@word); # chr() is evaluating the @word array in scalar
context,
# which returns the number of elements in the
array.
# this line is printing the characters 4, 3, 2,
1 (As you
# shift off the array) and finally '0' over and
over
# again when the array contains no elements.
}

# end

Here's another way of writing what (I think) you intended:

#!/usr/bin/perl

use warnings;
use strict;

my @word = (0x4E, 0x65, 0x72, 0x64);
print chr for @word;

# end

Hope this helps. Enjoy and let me know if you have any questions.

Thanks

Matt Shaw
Technical Architect
xwave, An Aliant Company
Desk: 506-389-4641
Cell: 506-863-8949
[EMAIL PROTECTED]


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




Re: Why did it print a happy face?

2004-03-02 Thread Tim
At 11:29 AM 3/2/04 -0500, you wrote:
This is a precursor to a real JAPH signeture (I need to learn more perl
before I can write a really obfuscated one), and I have already gotten it to
print what it was supposed to, but I changed print chr($letter); to print
chr(@word); to see if it would work, which is when I got the happy face
output in perl. Any ideas?
(By the way, I haven't fixed the while loop yet so be ready to quit fast to
read the output.)
Joel

#!usr/bin/perl

use Warnings;
use Strict;
my $h=4;
my @word = (0x4E, 0x65, 0x72, 0x64);
while ($h > 0) {
 $h++;
 $letter=shift @word;
 print chr(@word);
}
That while loop won't end.
chr takes a number; so @word is evaluated in a scalar context. you're 
printing chr(4) a whole lot of times.

change your loop control and print chr($letter).



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



Why did it print a happy face?

2004-03-02 Thread Joel
This is a precursor to a real JAPH signeture (I need to learn more perl
before I can write a really obfuscated one), and I have already gotten it to
print what it was supposed to, but I changed print chr($letter); to print
chr(@word); to see if it would work, which is when I got the happy face
output in perl. Any ideas?
(By the way, I haven't fixed the while loop yet so be ready to quit fast to
read the output.)

Joel

#!usr/bin/perl

use Warnings;
use Strict;

my $h=4;
my @word = (0x4E, 0x65, 0x72, 0x64);
while ($h > 0) {
 $h++;
 $letter=shift @word;
 print chr(@word);
}

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




Inserting strings into a file

2004-03-02 Thread Hemond, Steve
Hi again,

As you know, I am trying to insert a string at the beginning of a file
without overwriting its contents. Since my file is an HP/GL2 output
file, I put every hp/gl2 command and stack them into an array. I then
truncate the file, insert my specific string, and then put back all the
commands after that string :

open (FILE, "+>>$ARGV[0]") or die ("Can`t open file! : $!\n");

# We put contents of the file in a temporary scalar
my $in = ;

# Clear the file
truncate (FILE,0) or die ("Can't truncate file! : $! \n");


# Build the string to insert at the beginning
my $jobname = $ARGV[1]; #ARGV[0] is the file to be modified
my $pjl = '@PJL JOB NAME = "' . $jobname . '"' . '\n'; # What a dumb way
to build the string, any better ideas?
printf FILE "\e%-12345X ";
print $pjl;


As you can see, I wasn't able to build the string like this :
printf FILE "\e%-12345X @PJL JOB NAME = $ARGV[1] \n";

Because between double quotes the @ of @PJL will be interpolated, which
I don't want.

When running the script I get this error :
Use of uninitialized value in printf at ./hptable.pl line 126, 
line 1.
line 126 = printf FILE "\e%-12345X ";


I'd like first to know a better way to build the string (avoiding the @
interpolation).

Then I'd like to know why I get that error when printing the string in
the file.

Thanks!

Best regards,

Steve Hemond
Programmeur Analyste / Analyst Programmer
Smurfit-Stone, Ressources Forestieres
La Tuque, P.Q.
Tel.: (819) 676-8100 X2833
[EMAIL PROTECTED] 


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




Re: listing prime numbers in a range (Beginning Perl exercise)

2004-03-02 Thread James Edward Gray II
On Mar 1, 2004, at 6:14 PM, Stuart White wrote:


That's not really accurate.  What was said to that:

@list = "@list";

Creates a joined string of elements and replaces the
list with that one
item.  It's perfectly reasonable to stringify an
array, without
altering the array's contents:
print "@list\n";

I'm not sure I understand.
Try looking at some sample code:

my @list = qw(Apple Orange Banana);

print "@list\n";	# prints Apple Orange Banana; @list is NOT modified.

@list = "@list";
# the above basically means:
# @list = "$list[0] $list[1] $list[2]";
# since there is only one item on the right, it goes it $list[0] and 
the other
# indexes are cleared

print "@list\n";	# prints Apple Orange Banana, but list only has one 
string now

Now what I'd like to do to test whether or not I
have
a prime number is to get at each element in
@primelist, and use the modulus operator on each
element against each element in @list.  For
example:
$primelist[0] % $list[0]
$primelist[0] % $list[1]
$primelist[0] % $list[2]
$primelist[1] % $list[0]
$primelist[1] % $list[1]
$primelist[1] % $list[2]
$primelist[2] % $list[0]
$primelist[2] % $list[1]
$primelist[2] % $list[2]
and if the result doesn't equal 0 for every test
except for against itself, then I want to unshift
it
onto @primelist.

I thought I'd do this with nested foreach loops,
but
that didn't seem to work.  Any ideas?
Define "didn't seem to work"?  On second thought,
just post that nested
foreach and let us help you fix it.
James

Ok, I went with for loops.  As above, I want to get
the modulus of numbers in one array by comparing the
numbers of another array.  It's not doing what I
expect it to.  I'm not sure if the first loop is
really running either.  What am I doing wrong?  (Does
that question make sense?)
It makes perfect sense, yes, but I'm still missing one piece of 
information, the broken code you would like fixed.  As I said in my 
last message, "...just post that nested foreach and let us help you fix 
it."

Also, I'm getting an error: Use of uninitialized value
in modulus (%) at primeNumbers.pl line 40, 
line 1.
Illegal modulus zero at primeNumbers.pl line 40,
 line 1.
What do those errors mean exactly?  Thanks.
That's not an error, it's a warning.  It means one of the variables 
used in the % operation at line 40 doesn't have anything in it.  That 
test isn't really testing anything and that's probably why your program 
isn't running correctly.  Perl just thought you would like to know, 
since you asked for warnings.  Handy, eh?

James

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



Sharing functions and symbols between modules.

2004-03-02 Thread David le Blanc

Mostly as a test of Perl's namespace munging, I wanted to share
functions
and symbols ($var etc) between modules.

I came up with the following implemetation.

In a.pl you can say
-
use b;
use shared qw( $config =&hello );

sub hello
{
print "Hello World\n";
}
-
and in 'b.pm' you can say
-
use shared qw( $config &hello );
-

Now, '$config' imports '$shared::config' into the local namespace
so all code and any modules which declares 'use shared qw($config)' can
use $config as a package local variable and see the same data.

AND.

use shared qw( =&hello )

saves 'package::hello' in a hash in 'shared::export_map'.  Later
when a module calls

use shared qw( &hello )

it exports filter::hello to the local package.  The first time 
'hello' is called, the filter::autoload uses the 'export_map' to export
'hello' to the calling package and then uses goto to make sure the
function
gets called. (package::hello can't be exported directly, because it gets
imported in 'b' before it gets exported from 'main' due to the order of
execution of use/import() )

It works well, but the obvious question is, has it been done already?

Cheers.
David


[bits/ideas stolen from Exporter::Heavy.pm]

--- snip --
 
package shared;
 
require 5.001;
 
use strict;
use warnings;
 
use Exporter;
use Carp;
 
use vars qw( @ISA @EXPORTS $AUTOLOAD %export_map );
 
@ISA = qw( Exporter );
 
sub AUTOLOAD{
no strict 'refs';
 
# Perform a lookup for an exported function.  If found
# export it to the calling namespace and go to it, otherwise
# croak.
 
if( exists $export_map{$AUTOLOAD} ) {
my $pkg = caller;
my $i = $export_map{$AUTOLOAD};
*{"$pkg::$i->[1]"} = \&{$export_map{$AUTOLOAD}->[2]};
goto &{$export_map{$AUTOLOAD}->[2]}
}
Carp::croak "Undefined subroutine &".$AUTOLOAD;
}
 
sub import {
my @exports = @_[ 1 .. $#_ ];
 
my ( $type, $sym, $ssym );
my $pkg = caller;
 
no strict 'refs';
for $sym (@exports) {
 
# Handle shared export.  (function local to a package and shared
out,
# rather than shared import from 'shared::' namespace)

 
if( $sym =~ /^=(\W)?(.+)$/ ) {
Carp::croak "Symbol already shared from
$export_map{$2}->[2]"
if exists $export_map{$2};
$export_map{$2} = [ $1, $2, "${pkg}::${2}" ];
$export_map{"shared::$2"} = [ $1, $2, "${pkg}::${2}" ];
next;
}

# Install symbol in 'pkg' to refer to symbol in 'shared::'
namespace
# This will fail for functions, resulting in a call to
'AUTOLOAD' above.

$ssym = "shared::${2}" if $sym =~ /^(\W)?(.+)$/;

( *{"${pkg}::$sym"} = \&{"$sym"}, next )
  unless $sym =~ s/^(\W)//;

$type = $1;

*{"${pkg}::$sym"} =
$type eq '&' ? \&{"$ssym"}
  : $type eq '$' ? \${"$ssym"}
  : $type eq '@' ? [EMAIL PROTECTED]"$ssym"}
  : $type eq '%' ? \%{"$ssym"}
  : $type eq '*' ? *{"$ssym"}
  : undef;
}
}

1;

--- snip --
 
 

Regards,

David le Blanc

--  
Senior Technical Specialist  

I d e n t i t y   S o l u t i o n s 

Level 1, 369 Camberwell Road, Melbourne, Vic 3124   
Ph 03 9813 1388 Fax 03 9813 1688 Mobile 0417 595 550
Email [EMAIL PROTECTED]
  

The information transmitted is intended only for the recipient(s) to
which it is addressed and may contain confidential and/or privileged
material. Any review, retransmission, dissemination or other use of, or
taking of any action in reliance upon, this information by persons or
entities other than the intended recipient is prohibited. If you have
received this in error, please contact the sender and then delete it.
Identity Solutions has taken precautions to minimise the risk of
transmitting software viruses, but we advise you to carry out your own
virus checks on any attachment to this message. Identity Solutions
cannot accept liability for any loss or damage caused by software
viruses.



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




Re: Ternary operator question

2004-03-02 Thread James Edward Gray II
On Mar 2, 2004, at 12:41 AM, WC -Sx- Jones wrote:

Once upon a time $#array + 1 was the size of the array; obviously 
(scalar @array) now has the right size.
$#array + 1 still is the size of the array and it won't modify the 
array.  That's not what we were talking about.  We were talking about 
++$#array, which expands to $#array = $#array + 1.  Note the equal sign 
there, because it's what modifies the array.

James

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



Re: Trainset - initial release

2004-03-02 Thread James Edward Gray II
On Mar 2, 2004, at 7:01 AM, Gary Stainburn wrote:

On Monday 01 Mar 2004 4:40 pm, James Edward Gray II wrote:
[snip]
I'm not too found of mixing subroutines and methods, especially in 
the
same file.  Why don't you turn them into class methods, instead.  
This
especially makes sense for things like debug(), which the other
classes
can then call with Trainset->debug().
Wouldn't that confuse things regarding the %_DEBUG?  I don't see the
problem
with using subroutines within the class itself, although I could
understand
it if the subs were used outside the class it was in.
I doubt it, no.  In fact, I suspect it would be an improvement.  If 
you
have a:

my %_DEBUG;# lexical scoping makes this a class variable

in Trainset.pm that is setup will the needed information and provide a
class method interface to it, it's a 100% solution that needs now 
other
hashes or methods.  That seems ideal to me.
I must be missing something here, cos I can't see how it'll work.  If 
I create
Trainset/Utils.pm to hold the debug and validate routines, how can it 
access
%_DEBUG which is defined as a 'my' scoped hash in the Trainset package?
I was writing this before Trainset::Utils existed.  Put it in there 
instead and provide the access routines there too.

How would it know to use the %_DEBUG from Trainset::Track when called 
from
there?
You call Trainset::Utils->set_debug() to change it and 
Trainset::Utils->debug() to use it.

James

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



RE: listing prime numbers in a range (Beginning Perl exercise)

2004-03-02 Thread David le Blanc
> From: Stuart White [mailto:[EMAIL PROTECTED] 
> Sent: Tuesday, 2 March 2004 11:55 PM
> To: David le Blanc; [EMAIL PROTECTED]
> Subject: RE: listing prime numbers in a range (Beginning Perl 
> exercise)
> 
> 
> --- David le Blanc
> <[EMAIL PROTECTED]> wrote:
> > 
> > Just for the sake of it, and I apologise profusely
> > for the top posting..
> > 
> stuart>Hi David,
> 
> 
> > Here is a summary of the posted prime calculators
> > for testing your
> > results against.
> > 
> > >(1) Ohad
> 
> stuart>I saw his regexp soln.  I was attempting to
> stuart>solve it with arrays, loops and maybe hashes. 
> stuart>I figure that the exercise wouldn't be in the
> stuart>book before the regexp chapter if I couldn't do
> stuart>it easily (or without TOO much difficulty)
> stuart>without them.  That's all.
> 
> > >(2) Joseph
> stuart>I thought this one was a joke.  Partly because
> stuart>of the context it was sent in, partly because
> stuart>of what I saw it do.  I ran it, and it printed
> stuart>out a slew of numbers.  It didn't stop after a
> stuart>few minutes, so I ended the program.


You just have to realise that the script is printing the entire
array of primes EVERY time it finds a new one.  change the
'while (1)' to 'while( $#primes < 2000 )' to only find 1000
primes, and move the 'print' to after the loop.

> 
> 
> > >(3) me (Hey, it's a Mee Too!)
> >
> #---
> > $max=shift||17393;
> > %notprime=();
> > @prime=();
> > 
> > for $n (2..$max){
> > unless($notprime{$n}){
> > push @prime,$n;
> > $notprime{$_*$n}=1 for 2..$max/$n;
> > }
> > }
> > 
> > print "Found $#prime prime numbers..".$/;
> > print "@prime\n";
> >
> #---
> > 
> > Brief explanation..
> > (1) 
> sounds neat.
>  
> > (2) Joseph posted a calculator which uses the
> > feature of prime numbers
> > that the 
> > largest number you need to divide it by is the
> > square root of itself
> > ($_**0.5)
> > and that you only need to test if the number you
> > are examining is
> > divisible
> > (ie mod==0) by another prime you have already
> > found.  Hence, very
> > quick and
> > very cpu/memory cheap.  Why not test against
> > every number?  If you
> > test against
> > a non-prime number, you are simply testing
> > against a multiple of a
> > prime of
> > course.
See above.  It does work afaik.
> 
> stuart>Ahh, this makes sense, sortof.  I'm going to
> stuart>need to look at the code again and your
> stuart>explanation.  This was printing many, many,
> stuart>many numbers, some of which sure didn't look
> stuart>like they were primes.  The sheer number plus
> stuart>the proximity of them to each other in
> stuart>cardinal? order (2341  2347 2443 etc) (these
> stuart>numbers are used to illustrate my probably
> stuart>improper use of cardinal, I'm not implying that
> stuart>those numbers were outputted by the program)
> stuart>made me think that some weren't primes.
> 
> 
> > 
> > (3) A very simple implementation of an erogenous
> > sieve (iud? did I say
> > that wrong?)
> > which keeps all primes in '@primes' and all
> > 'eliminated' entries in
> > '%notprime'.
> > quick, but likely more memory intensive than
> > (2).
> 
> This one is a bit confusing. 
> $max=shift||17393;

> stuart>I thought shift was to remove an element from
> stuart>the beginning of an array, but it's being used
> stuart>in scalar context here.  Why?  And what is it
> stuart>doing?

When 'shift' has no argument, it shifts '@_' which is parameter
arguments in a function, and command line arguments elsewhere.

$max = shift will grab the first command line argument. If 
there isn't one, shift == undef, so perl will complete the 'x||y'
expression by evaluating 'y'.  If 'shift' returns a number, the 'x||y'
expression is shortcut.

Hence, $max = first argument OR 17393 if there isn't one.

> 
>  %notprime=();
> > @prime=();
> > 
> > for $n (2..$max){
> stuart>this makes me think that you were somehow
> stuart>assigning a number to $max above.  But where
> stuart>does 17393 come in?  Why not 17394, or 18000?

17393 is a completely magic number it just so happens where are
exactly 2000 prime numbers between 2 and 17393 inclusive.

> 
> 
> > unless($notprime{$n}){
> > push @prime,$n;
> > $notprime{$_*$n}=1 for 2..$max/$n;
> stuart>I'm not sure I understand this line directly
> stuart>above.  What I think it says is that it is
> stuart>accessing the value within the %notprime hash
> stuart>where the key equals the last inputted number
> stuart>which I suppose is $n and $_ if $n was pushed
> stuart>onto @prime, but just $_ if $n was not pushed
> stuart>onto @prime.  I don't get the "=1" part
> stuart>though.  What is that doing?  I'm assuming that
> stuart>is a for loop there that is working like a
> stuart>foreach loop?  but I'm not quite sure what it's
> stuart>doing.
> 

How about:
for($i= $n*2; $i<$max

Re: Checking filenames?

2004-03-02 Thread Jenda Krynicky
From: WC -Sx- Jones <[EMAIL PROTECTED]>
> Jenda?
> 
> This is the partial original post -
> 
> Jas wrote:
> > Wouldn't this be better?
> > 
> > my $year = "";
> > my $month = "";
> > my $day = "";
> > 
> > if($file =~ /^(\d{4})(\d{2})(\d{2})-www.tar.gz$/) {
> >   $year = $1;
> >   $month = $2;
> >   $day = $3;
> > 
> > my $chk = "$month - 1";
> 
> Here - this is weird =)
> 
> "03" in numerical context is 3.
> 
> File name was 20040301 - collapses to 200431 -
> Not a match IMHO.

I see. You did not include that line in the email I was responding 
to. So I did not see anything that could provide numerical context.

my $chk = "$month - 1";
is simply wrong. If $month was '03' then $chk will be '03 - 1'.
And if it was 
my $chk = $month - 1;
then $chk would be 2. Which is much better, but needs to be handled 
properly.

If Jas wanted a date one month before now he'd need something like:

$month--;
if ($month == 0) {
$month = 12;
$year--;
}
$datestamp = sprintf "%04d%02d%02d", $year, $month, $day

> > foreach($file ! $chk) {

This line is a clear syntax error.

> Maybe I am totally confused - I have been working on WebSphere.  Yes,
> I plead complete insanity.

No I guess it's me who's confused. I am stateless. I handle each 
email separately, not remembering anything from the previous ones. 
(Well almost.) I do not keep the old ones and with the amount of spam 
and viruses I get looking up something in the "Deleted" folder is 
rather hard.

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: listing prime numbers in a range (Beginning Perl exercise)

2004-03-02 Thread David le Blanc
> -Original Message-
> From: Paul Johnson [mailto:[EMAIL PROTECTED] 
> Sent: Wednesday, 3 March 2004 12:13 AM
> To: David le Blanc
> Cc: [EMAIL PROTECTED]
> Subject: RE: listing prime numbers in a range (Beginning Perl 
> exercise)
> 
> 
> David le Blanc said:
> 
> > Here is a summary of the posted prime calculators for testing your
> > results against.
> 
> And here's a previous thread with few more scripts:
> 
> http://groups.google.com/groups?hl=en&lr=&ie=UTF-8&oe=UTF-8&th
readm=005101c25d82%2475841fc0%243e861199%40pcf594.nmc->
m.dtag.de&rnum=1&prev=/groups%3Fhl%3Den%26lr%3D%26ie%3DUTF-8%2
6oe%3DUTF-8%26selm%3D005101c25d82%252475841fc0%25243e861199%>
2540pcf594.nmc-m.dtag.de

Great stuff here!

> 
> Apologies for the ghastly URL.

For the benefit of those tripped by the ghastly URL provided, here is an
alias provided by tinyurl.com

http://tinyurl.com/23mzl

> 
> You could also search for "dealing with Prime Numbers" in 
> google groups.
> 
> -- 
> Paul Johnson - [EMAIL PROTECTED]
> http://www.pjcj.net
> 
> 

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




Re: Automatically write in uppercase

2004-03-02 Thread Paul Johnson

James Edward Gray II said:

> On Feb 29, 2004, at 6:30 AM, John wrote:
>
>> That's a nice method but i would prefer to activate the CAPS-LOCK and
>> user
>> write in capitals in my text entry widget
>
> I would prefer you didn't.  ;)
>
> The keyboard takes commands from me, not the computer.  If a program
> started monkeying with my control of such a device, it would find my
> trash can, mighty quick.

Come on people.  Maybe John has a good reason for wanting Caps Lock to be on.

I have also written a Perk/Tk program in which I would like to control
Caps Lock.  The program is used as part of a programme to help people with
dyslexia improve their reading skills.  In part this involves displaying
text on the screen and having the student type it in.  In the very early
stages of the program the letters on the screen need to match those on the
keyboard - that is they need to be uppercase - otherwise the student may
have problems locating the correct key to press.  Obviously, at this sort
of level it is not desirable to have the student also hold down the Shift
key.

I have solved this by accepting lowercase input as uppercase, and in my
case this works well as I am not using a text entry widget, but a Caps
Lock solution might also be nice.  Unfortunately, I don't think a cross
platform solution exists, but if anyone knows of one, or if John tells us
which platform he is concerned about and anyone knows of a solution for
that platform, please speak up.

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


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




RE: ENV variables and custom 404 error page

2004-03-02 Thread Bob Showalter
Bryan Harris wrote:
> > # do this. make sure that this line is the
> > # ONLY thing you print out to the browser.
> > print "Location: http://rightplace.com/\n\n";;
> 
> 
> Wow, this is cool!  Where is this documented?  I'm interested in
> learning about other things like this...

This is part of the HTTP spec, which is defined in RFC 2616:

http://www.w3.org/Protocols/rfc2616/rfc2616-sec14.html#sec14.30

The CGI module can produce a redirect header as well, with its redirect()
method.

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




RE: listing prime numbers in a range (Beginning Perl exercise)

2004-03-02 Thread Paul Johnson

David le Blanc said:

> Here is a summary of the posted prime calculators for testing your
> results against.

And here's a previous thread with few more scripts:

http://groups.google.com/groups?hl=en&lr=&ie=UTF-8&oe=UTF-8&threadm=005101c25d82%2475841fc0%243e861199%40pcf594.nmc-m.dtag.de&rnum=1&prev=/groups%3Fhl%3Den%26lr%3D%26ie%3DUTF-8%26oe%3DUTF-8%26selm%3D005101c25d82%252475841fc0%25243e861199%2540pcf594.nmc-m.dtag.de

Apologies for the ghastly URL.

You could also search for "dealing with Prime Numbers" in google groups.

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


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




Re: Trainset - initial release

2004-03-02 Thread Gary Stainburn
On Monday 01 Mar 2004 4:40 pm, James Edward Gray II wrote:
[snip]

> >> I'm not too found of mixing subroutines and methods, especially in the
> >> same file.  Why don't you turn them into class methods, instead.  This
> >> especially makes sense for things like debug(), which the other
> >> classes
> >> can then call with Trainset->debug().
> >
> > Wouldn't that confuse things regarding the %_DEBUG?  I don't see the
> > problem
> > with using subroutines within the class itself, although I could
> > understand
> > it if the subs were used outside the class it was in.
>
> I doubt it, no.  In fact, I suspect it would be an improvement.  If you
> have a:
>
> my %_DEBUG;# lexical scoping makes this a class variable
>
> in Trainset.pm that is setup will the needed information and provide a
> class method interface to it, it's a 100% solution that needs now other
> hashes or methods.  That seems ideal to me.

I must be missing something here, cos I can't see how it'll work.  If I create 
Trainset/Utils.pm to hold the debug and validate routines, how can it access 
%_DEBUG which is defined as a 'my' scoped hash in the Trainset package?

How would it know to use the %_DEBUG from Trainset::Track when called from 
there?

>
> James

-- 
Gary Stainburn
 
This email does not contain private or confidential material as it
may be snooped on by interested government parties for unknown
and undisclosed purposes - Regulation of Investigatory Powers Act, 2000 


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




RE: listing prime numbers in a range (Beginning Perl exercise)

2004-03-02 Thread David le Blanc

Just for the sake of it, and I apologise profusely for the top posting..

Here is a summary of the posted prime calculators for testing your
results against.

>(1) Ohad
#---
perl -e 'print"@{[grep{(1x$_)!~/^(11+?)\1+$/}2..shift||1e2]}\n"'

#---
>(2) Joseph
#---
my @primes = (2);
my $candidate = 3;
while(1) {
   my $limit = $candidate ** 0.5;
   my $has_factor = 0;
   foreach (@primes) {
  if ($_ > $limit) {
 push @primes, $candidate;
 last;
  }
  unless ($candidate % $_) {
 $has_factor = 1;
 last;
  }
   }
   unless ($has_factor) {
  print "$_ " foreach @primes;
  print "\n";
   }
   $candidate++;
}
#---
>(3) me (Hey, it's a Mee Too!)
#---
$max=shift||17393;
%notprime=();
@prime=();

for $n (2..$max){
unless($notprime{$n}){
push @prime,$n;
$notprime{$_*$n}=1 for 2..$max/$n;
}
}

print "Found $#prime prime numbers..".$/;
print "@prime\n";
#---

Brief explanation..
(1) Ohad posted an obfuscated calculator which runs the array
(2..) through
grep().  The pattern in grep is '(1 x $_) !~ /^(11+?)\1+$/' which is
a tricky
way of getting perls enormously powerful regex exgine to determine
if there is
a way of dividing a string of length int($_) characters into a
number of same length
substrings.   Probably memory hungry, but definitely cpu hungry for
the regexp.
Note that for any value '$x', "(1 x $x) !~ /^(11=?)\1+$/" will
return true if the
number is prime.   Excellent way to perform a (quick?) once off test
against a
known number without calculating every other prime.  It uses the
obscure perl
@{[ expr ]} to magically interpolate code within quotes.

(2) Joseph posted a calculator which uses the feature of prime numbers
that the 
largest number you need to divide it by is the square root of itself
($_**0.5)
and that you only need to test if the number you are examining is
divisible
(ie mod==0) by another prime you have already found.  Hence, very
quick and
very cpu/memory cheap.  Why not test against every number?  If you
test against
a non-prime number, you are simply testing against a multiple of a
prime of
course.

(3) A very simple implementation of an erogenous sieve (iud? did I say
that wrong?)
which keeps all primes in '@primes' and all 'eliminated' entries in
'%notprime'.
quick, but likely more memory intensive than (2).

Cheers.
David


--  
Senior Technical Specialist 
I d e n t i t y   S o l u t i o n s 

Level 1, 369 Camberwell Road, Melbourne, Vic 3124   
Ph 03 9813 1388 Fax 03 9813 1688 Mobile 0417 595 550
Email [EMAIL PROTECTED] 
 

> -Original Message-
> From: Stuart White [mailto:[EMAIL PROTECTED] 
> Sent: Tuesday, 2 March 2004 11:14 AM
> To: James Edward Gray II
> Cc: [EMAIL PROTECTED]
> Subject: Re: listing prime numbers in a range (Beginning Perl 
> exercise)
> 
> 
> > That's not really accurate.  What was said to that:
> > 
> > @list = "@list";
> > 
> > Creates a joined string of elements and replaces the
> > list with that one 
> > item.  It's perfectly reasonable to stringify an
> > array, without 
> > altering the array's contents:
> > 
> > print "@list\n";
> > 
> 
> I'm not sure I understand.
> 
> > 
> > That can just be if ($_ % 2), if you prefer.  Zero
> 
> That makes perfect sense.  Thanks.
> 
> > >  {
> > >   unshift(@primelist, $_);
> > >   @primelist\n";  
> > 
> > The above line is not a valid Perl statement.
> > 
> 
> Oh, the "@primelist\n";  ?  I'm not sure how that got
> there...
> 
> > > Now what I'd like to do to test whether or not I
> > have
> > > a prime number is to get at each element in
> > > @primelist, and use the modulus operator on each
> > > element against each element in @list.  For
> > example:
> > > $primelist[0] % $list[0]
> > > $primelist[0] % $list[1]
> > > $primelist[0] % $list[2]
> > > $primelist[1] % $list[0]
> > > $primelist[1] % $list[1]
> > > $primelist[1] % $list[2]
> > > $primelist[2] % $list[0]
> > > $primelist[2] % $list[1]
> > > $primelist[2] % $list[2]  
> > >
> > > and if the result doesn't equal 0 for every test
> > > except for against itself, then I want to unshift
> > it
> > > onto @primelist.
> > >
> > > I thought I'd do this with nested foreach loops,
> > but
> > > that didn't seem to work.  Any ideas?
> > 
> > Define "didn't seem to work"?  On second thought,
> > just post that nested 
> > foreach and let us help you fix it.
> > 
> > James
> > 
> 
> Ok, I went with for loops.  As above, I want to get
> the modulus of numbers in one array by comparing the
> numbers of another array.  It's not doing what I
> expect it to.

Re: Reading File & grep according item 5 and sorting

2004-03-02 Thread Bjorn Van Blanckenberg
On 28-feb-04, at 20:32, R. Joseph Newton wrote:

Bjorn Van Blanckenberg wrote:

let say that the file contains these items (every item is seperated
with a tab)
...

one  title3   state3   name3   pre   number3
dip  title6   state6   name6   pre2   number6
So what changes have you made in the code to reflect this diffeence in
specification.  Let us know how *your* adaptations work.
Joseph

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

#!/usr/bin/perl

use strict;
use Getopt::Long;
GetOptions(\my %opt, 'filepath=s');

my $filepath = (%opt->{'filepath'});

my @fields = ();
my @sorted = ();
my $lastbit = 1;
my @bits = ();
open(INFILE,$filepath);

chomp(@fields = );

@sorted =
map { $_->[0] }
sort { $a->[5] cmp $b->[5] }
map { [ $_ , (split /\t/) ] } @fields;
foreach (@sorted){
@bits = split;
print "\n" if ($bits[4] ne $lastbit);
print "$_\n";
$lastbit=$bits[4];
}
this is what I have know but al it does is sorting according item 5 but 
want it to look in all the items of column 5 and if it contains item 5
print it in one block and then the next block separated with an return 
so that

one  title   state   name   testing   number
two  title2   state2   name2   final   number2
one  title3   state3   name3   pre   number3
four  title4   state4   name4   tesing2   number4
six  title5   state5   name5   testing3   number5
dip  title6   state6   name6   pre2   number6
fun  title7   state7   name7   final2   number7
becomes

one  title   state   name   testing   number
four  title4   state4   name4   tesing2   number4
six  title5   state5   name5   testing3   number5
two  title2   state2   name2   final   number2
fun  title7   state7   name7   final2   number7
one  title3   state3   name3   pre   number3
dip  title6   state6   name6   pre2   number6
--
  Oooo.
 oooO( )
 ( )   )   /
  \   (   (_/
\_)
Thanks
Bjorn Van Blanckenberg
--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
 



RE: subroutine definitions

2004-03-02 Thread David le Blanc
> -Original Message-
> From: zsdc [mailto:[EMAIL PROTECTED] 
> Sent: Tuesday, 2 March 2004 4:54 PM
> To: Andrew Gaffney
> Cc: 'beginners'
> Subject: Re: subroutine definitions
> 
> Andrew Gaffney wrote:
> 
> > zsdc wrote:
> > 
> >> Confusion? You should read 6th Apocalypse by Larry Wall and the 
> >> appropriate Exegesis by Damian Conway:
> >>
> >> http://dev.perl.org/perl6/apocalypse/A06.html
> >> http://dev.perl.org/perl6/exegesis/E06.html
> >>
> >> Now, _that_ is confusing. :)
> > 
> > I think that's an understatement. Blood is coming out of my 
> ears after 
> > reading a few pages of the first one...
> 
> Well, that's Apocalypse after all...

I t-ttt-think tthh-there shouldl-dd ha be-e-en a health-th-tt-th
warr-r-rn-nning on that th-th-th-thingg-gg.

thud [].



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




RE: print a 3D array

2004-03-02 Thread David le Blanc
> -Original Message-
> From: R. Joseph Newton [mailto:[EMAIL PROTECTED] 
> Sent: Tuesday, 2 March 2004 7:20 PM
> To: John
> Cc: Perl Beginners
> Subject: Re: print a 3D array
> 
> John wrote:
> 
> > Problem with my array
> >
> > 0Tk::Error: Can't use string ("ARRAY(0x22bdfb0)") as an 
> ARRAY ref while
> > "strict
> 
> > refs" in use at 
> C:\DOCUME~1\ADMINI~1\LOCALS~1\Temp\dir635.tmp\gui.pl line
> > 307, <
> > DATA> line 164.
> 
> >
> 
> You have shown us the error message here.  That is good.  
> Unfortunately, you do
> not show us line 307 and the lines just preceding it.  That's 
> bad.  It leaves us
> with only specualtion.
> 

If you want speculation, how about..

You used the array reference as a KEY in a hash, and are trying to
deref the value of 'key'.

Eg, 

[EMAIL PROTECTED] = [EMAIL PROTECTED];

for( keys %X ) {
print $_->[0];
}

Anything which is used as a key becomes a string, and can no longer be
used as an actual reference.  Remember 'ARRAY(0x22bdfb0)' is the scalar
representation of a reference, not an actual reference.  You cannot 
convert the scalar back to a reference.  You  can try, with something
like '$ref = unpack("p",0x22bdfb0)'  and I'd love to know if it worked.



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




Re: print a 3D array

2004-03-02 Thread R. Joseph Newton
John wrote:

> Problem with my array
>
> 0Tk::Error: Can't use string ("ARRAY(0x22bdfb0)") as an ARRAY ref while
> "strict

> refs" in use at C:\DOCUME~1\ADMINI~1\LOCALS~1\Temp\dir635.tmp\gui.pl line
> 307, <
> DATA> line 164.

>

You have shown us the error message here.  That is good.  Unfortunately, you do
not show us line 307 and the lines just preceding it.  That's bad.  It leaves us
with only specualtion.

This is really wierd actually.  I tried screwing up an array ref by quoting, and
it didn't work at all.  The ref still worked as a ref.  Looking at theerror
message above, I can't imagine how you got to this point.  An actual array
reference would look like:
ARRAY<0x22bdfb0>
not
ARRAY(0x22bdfb0)
although the two are almost undistinguishable in the default font used by
cmd.exe.

I am at a loss.  Short of something truly insane, like trying to type in the
string value of an array ref, I do not understand how the strings shown in the
error message would ever get into the compiler.

Show us the code of the indicated lines, please.

Joseph


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