Re: Determine upload file type

2008-06-20 Thread Beginner
On 20 Jun 2008 at 11:43, Mimi Cafe wrote:
 I need to write a cgi program to enable our users to upload files using the
 web browser, but I am not sure how to figure out the type of file the user
 wants to upload (e.g text or binary file). Can CGI.pm accomplish this
 automatically?
 
 Any suggestions welcome.


Have a look at this from the highly secretive CGI documentation :-)

When a file is uploaded the browser usually sends along some 
information along with it in the format of headers. The information 
usually includes the MIME content type. Future browsers may send 
other information as well (such as modification date and size). To 
retrieve this information, call uploadInfo(). It returns a reference 
to an associative array containing all the document headers.

   $filename = param('uploaded_file');
   $type = uploadInfo($filename)-{'Content-Type'};
   unless ($type eq 'text/html') {
  die HTML FILES ONLY!;
   }


Dp.


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




Re: Could not open testfile.txt: No such file or directory

2008-05-30 Thread Beginner
Hi,

Did you mean to mail the cgi list?

On 30 May 2008 at 13:04, Mimi Cafe wrote:


 use constant DEFAULT_REPORTDIR = .\\compare_report;

Is this a windows path? You can and probably should always use '/' 
for directory path separators or in this case 'compare_report' would 
do.

 my $master_list = ;
 my @compare_lists = ;
 my $help = ;
 
 Getopt::Long::Configure (ignorecase);
 
 GetOptions(
  master=s = \$master_list,
  compare:s = [EMAIL PROTECTED],
  help|?! = \$help,
 );
 
 usage() if $help;
 @compare_lists = split(' ',join(' ',@compare_lists));
 foreach (@compare_lists){
  die File $_ does not exist or it's empty. Please check the file try
 again.\n unless -s $_;
 }
 
 
 #foreach (@compare_lists){print $_\n;} # This prints the CLI arguments
 correctly.
 #

What is the output from the above for loop?
 
 my $outputdir = DEFAULT_REPORTDIR;
 unless (-d $outputdir){
  mkdir ($outputdir) or die could not create dir for $outputdir: $!\n;
 }
 
 # Read the master list and populate our array.
 open (MASTERFILE, , $master_list) or die Could not open $master_list for
 reading: $!\n;
 my @master_clients = MASTERFILE;
 close MASTERFILE;
 ##
 #print master list starts below:\n;
 #foreach (@master_clients){print $_\n;}exit;
 ##
 my (%inputclient,$list);
 
 # Read the other files and compare the content to the master client list.
 foreach $list (@compare_lists){
  # Output file name set of element curerently processed.
  # Open file to read from.
  open(INPUTFH, , $list) or die Could not open $list for reading:
 $!\n; # Could

No need for  here. $list will do or $list if you want to hammer 
home the point that your reading in.

Consider using $inputfh for your file handle, there more portable.

What is the exact error message line, include the value of $list? 
It's this that the OS can't read/find. Post that and it might be 
clearer where the problem is.

Good luck,
Dp.





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




Re: Suggestions for a simple configuration management web application

2008-03-12 Thread Beginner
On 11 Mar 2008 at 11:54, Richard wrote:

 Hey all,
 
 I am trying to find a simple, modular web based configuration
 application and am having a little trouble.  Basically, I need
 something to do some simple configurations on an appliance similar to
 something like a laser printer.  You know the little web based menu
 you get when you hit your local Lexmark C530dn or HP LaserJet and it
 allows you to change the IP address, set the printer name, and get
 some feedback on how many pages you've printed?  That's what I want.

Your requirements aren't as straight forward as you might think. You 
want an appliance that can change the config of any device. It sounds 
like you assuming that all hardware devices have a standard API for 
configuring. They don't. Each manufacturer will have their own. You 
might be able to use arp to configure the mac address/IP address on 
the device but that's about all you could do with arp. Getting page 
counts and other hardware specific information will require detailed 
access to the hardware API if one exists. 

 I tried to look at webmin and possibly building my own modules, but
 I'm based on Debian and webmin has fallen out of favor.  My next
 thought was to write a little something, possibly based on
 TemplateToolkit but that seems a little excessive.  I also played
 around with the idea of ripping the GUI out of m0n0wall and using it
 to base my stuff on, but that didn't seem very clean.

Won't cups provide you with some of the functionality you want.

 I would rather use and contribute to something that is pre-existing in
 the OSS world than to start my own project.  My time is limited and
 I'm not that great of a programmer.  :)  Anyway, it's hard to believe
 that no-one has ever created a simple little web app that can be
 extended with modules.  Do you know of anything that I could use as a
 jumping off point?

An good application framework would be Catalyst but I am not sure 
that a framework is what your after.


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




Send a file

2008-02-19 Thread Beginner
Hi,

I am trying to send a file in response to a request but am having 
trouble.

Here's what I have so far. I am not certain what the headers should 
be. I am not getting any more info from my error_log except Premature 
end of script headers.


my $s = (stat($file))[7];

my $filename = $user.'.csv';
seek $fh,0,0;
print header(-type=text/tab-separated-values,-Content_length=$s,
-Content_Disposition=attachment;filename=$filename);
print $fh;
close($fh);


Can anyone offer some advice?
Thanx,
Dp.


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




Re: What is the function value in perl?

2008-01-12 Thread Beginner
I know how to read the key from the keyboard now but when I use the
Readkey to read the F3 key, it only show 0 for the key, and it is same
as other Fx key...

Is that any other way to find other those Fx key ASCII value in perl?


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




Re: What is the function value in perl?

2008-01-07 Thread Beginner
On 1月5日, 下午6時19分, [EMAIL PROTECTED] (Peter Scott) wrote:
 On Fri, 04 Jan 2008 09:04:48 -0800, Beginner wrote:
  Hi all, Can any body teach me how to input the function key in perl?
  such as Esc, F1, F2, F3, F4...
  I' m programming something with perl to work with IBM AS400 system,
  and it needs to input some key like F3, F9..

 Type perldoc -q single and that should get you started.

 --
 Peter Scotthttp://www.perlmedic.com/http://www.perldebugged.com/

Do you mean I do a search for  perldoc -q single  at yahoo or
google?


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




What is the function value in perl?

2008-01-04 Thread Beginner
Hi all, Can any body teach me how to input the function key in perl?
such as Esc, F1, F2, F3, F4...
I' m programming something with perl to work with IBM AS400 system,
and it needs to input some key like F3, F9..

Thanks!!


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




Extract attribute from huge xml file

2007-12-10 Thread Beginner
Hi,

I have a huge XML file, 1.7GB, 53080215 lines. I am trying to extract 
an attribute from each record (code=). I several problems one of 
which is the size of the file is making it painful to test my scripts 
and methods for parsing.

I would like to extract a few hundred records (by any means) so I can 
experiment.  I think XPath is the way to go here. The file 
(currently) sits on a *nix system but I was going to do the parsing 
to on a Win32 workstation rather than steal all the memory on a 
server.

Below is a sample of some data. I have XML::XPath installed, there 
doesn't seems to be a libXML2 for Win32 . This is my first effort but 
I haven't been able to run it fully as my workstation began to page 
severely after a while. So I would like so hints before try again as 
each attempt takes ages.

TIA,
Dp.


===
#!/bin/perl

use strict;
use warnings;
use XML::XPath;
use XML::XPath::XMLParser;

my $xmp = XML::XPath-new(filename = 'myfile.xml');

my $nodeset = $xmp-find('/records/record/');

foreach my $node ($nodeset-get_nodelist) {  
my $attrib = $node-getNodeType('ATTRIBUTE_NODE');
print $attrib\n;
}
=

?xml version = 1.0 encoding= utf-8?
records
record code=65020/0002
display_number65020/003/display_number
titleMoulded resistors in synthetic resin/title
created_date05-Mar-85/created_date
updated_date15-Nov-07/updated_date
restrictions
/restrictions
/image
...snip

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




Re: modify mirror list - CPAN

2007-12-03 Thread Beginner
On 24 Oct 2007 at 7:22, Tom Phoenix wrote:

 On 10/24/07, Beginner [EMAIL PROTECTED] wrote:
 
  I want to modify the mirror list that I selected when I did a first
  run of perl -MCPAN.
 
 You can modify your settings within a CPAN shell session by using the
 o command. But it may be easier to directly edit the settings file,
 which is probably in a file called MyConfig.pm somewhere under your
 CPAN build directory. For me, that's ~/.cpan/CPAN/MyConfig.pm , but
 your build directory may located elsewhere. Good luck with it!


I completely removed the .cpan directory but still the old url list 
was being used. I eventually found the url in the file 
/usr/lib/perl5/5.8.6/CPAN/Config.pm. This is on FC4. Once I removed 
the dead mirror, my cpan installs are much less painful.

Thanx.
DP.



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




Re: seek and tell

2007-11-30 Thread Beginner
On 30 Nov 2007 at 10:35, John W.Krahn wrote:

 On Friday 30 November 2007 09:07, Beginner wrote:

 Hello,

 [ SNIP ]
 
  $| = 1;
 
 You never print to STDOUT so that line is superfluous.
  my $in = 0;
 
  my $sRootPath = 'e:/';
 
  my
  ($osVolName,$lVolName,$ouSerialNum,$ouMaxNameLen,$osFsType,$ouFsFlags
 , $lFsType);
  GetVolumeInformation( $sRootPath, $osVolName, $lVolName,
  $ouSerialNum, $ouMaxNameLen, $ouFsFlags, $osFsType, $lFsType );
 
 You can declare and define the variables at the same time:
 
 GetVolumeInformation( $sRootPath, my ( $osVolName, $lVolName, 
 $ouSerialNum, $ouMaxNameLen, $ouFsFlags, $osFsType, $lFsType ) );
 
 But it looks like the only variables you are using there are $sRootPath 
 and $osVolName so perhaps this will work:
 
 GetVolumeInformation( $sRootPath, my $osVolName, undef, undef, undef, 
 undef, undef, undef );
 
 Or perhaps even just:
 
 GetVolumeInformation( $sRootPath, my $osVolName );
 
 
  my $file = $osVolName.'.txt';
  open(LOG,$file) or die Can't write $file: $!\n;
  print LOG Contents of Disk with Volume Name $osVolName\n\n;
  my $pos = tell LOG;
 
  print LOG \n\n\n\n\n\n\n\n\n\n\n\n; # Add space for summary.
  print LOG -\n;
 
  my @dirs;
  my %uniq;
  find(\files,$sRootPath);
 
  # Summary text.
  seek(LOG, $pos, 0);
 
 You should use the seek constants from the Fcntl module:
 
 use Fcntl ':seek';
 
 seek LOG, $pos, SEEK_SET or die Cannot seek on '$file' $!;
 
 
  print LOG CD Has ,($#dirs + 1), folders: ;
 
 ($#dirs + 1) may or may not be the correct number.  Better to use the 
 actual number of @dirs elements:
 
 print LOG CD Has , scalar @dirs, folders: ;
 
 
  for (@dirs) {
  print LOG $_, ;
  }
 
 That will print ', ' at the end of the line.  You probably want to do 
 this instead:
 
 print LOG join ', ', @dirs;
 
 
  print LOG \n\nTotal number of files: $in\n;
 
 
  sub files {
  my $section;
  ($section) = ($File::Find::dir =~ /$sRootPath(\w{1})/);
 
 You can declare and define the variables at the same time:
 
   my ( $section ) = $File::Find::dir =~ /$sRootPath(\w{1})/;
 
 (\w{1}) could also be written as (\w).  You should anchor the pattern 
 as the RootPath should only occur at the beginning of the string.  You 
 should probably quotemeta the string as it may contain regular 
 expression meta-characters:
 
   my ( $section ) = $File::Find::dir =~ /\A\Q$sRootPath\E(\w)/;
 
 
  # unique folder only
  if (! exists($uniq{$section})  $section =~ /\w/) {
 
 The test '$section =~ /\w/' seems redundant.  Perhaps that should be 
 'defined $section' instead.
 
   if ( defined( $section )  ! exists( $uniq{ $section } ) ) {
 
 
  push(@dirs,$section);
  $uniq{$section} = 0;
  }
  # Count the files and print em'
  if ($_ =~ /jpg/i) {
 
 If you are trying to match a '.jpg' file extention then you should 
 anchor the pattern so you don't match 'jpg' somewhere in the middle of 
 the file name:
 
   if ( /\.jpg\z/i ) {
 
 
  ++$in;
  print LOG $section\t$_\n;
  }
  }
 
 John
 -- 
 use Perl;
 program
 fulfillment

Thanx to you both. I appreciate now that \n is 2 bytes and I should 
be working in bytes with seek/tell.

John an added thanx for the line by line comments particulatly the 
join and scalar tips.

Much appreciated.
Dp.


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




seek and tell

2007-11-30 Thread Beginner
Hi,

Can someone spot and explain what I am doing wrong.

I have a script that should read the contents of a CD (on Win32). I 
want a summary at the top of the page of what I've found. I use find 
to count the files and dirs and I want the total files ($in) to be a 
the top before I list the files. Once I have printed the header stuff 
(Content of ...), I store the position of the filehandle so I can 
come back to that position later but I am always truncating existing 
text so my output reads like this:

CD Has 4 folders:
a, e, g, n, 

Total number of files: 38486
38486jpg
1224.jpg
1225.jpg
...

When i desire this:

CD Has 4 folders:
a, e, g, n, 

Total number of files 38486
--
1221.jpg
1222.jpg
...

The text starts in the expected place but although I have created 12 
newlines for the summary text (that should only use 9 lines) the text 
crashes into listing sucking up any spare newlines as it goes.
Am I making sense?? Any ideas?
Dp.

=

use strict;
use warnings;
use Win32API::File 0.08 qw(GetVolumeInformation );
use File::Find;

$| = 1;
my $in = 0;

my $sRootPath = 'e:/';

my 
($osVolName,$lVolName,$ouSerialNum,$ouMaxNameLen,$osFsType,$ouFsFlags,
$lFsType);
GetVolumeInformation( $sRootPath, $osVolName, $lVolName, 
$ouSerialNum, $ouMaxNameLen, $ouFsFlags, $osFsType, $lFsType );

my $file = $osVolName.'.txt';
open(LOG,$file) or die Can't write $file: $!\n;
print LOG Contents of Disk with Volume Name $osVolName\n\n;
my $pos = tell LOG;

print LOG \n\n\n\n\n\n\n\n\n\n\n\n; # Add space for summary.
print LOG -\n;

my @dirs;
my %uniq;
find(\files,$sRootPath);

# Summary text.
seek(LOG, $pos, 0);
print LOG CD Has ,($#dirs + 1), folders: ;
for (@dirs) {
print LOG $_, ;
}
print LOG \n\nTotal number of files: $in\n;


sub files {
my $section;
($section) = ($File::Find::dir =~ /$sRootPath(\w{1})/);

# unique folder only
if (! exists($uniq{$section})  $section =~ /\w/) { 
push(@dirs,$section);
$uniq{$section} = 0;
}
# Count the files and print em'
if ($_ =~ /jpg/i) {
++$in;
print LOG $section\t$_\n;
}
}


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




Re: How can I assign system() call to a Variable

2007-11-14 Thread Beginner
On 13 Nov 2007 at 19:11, Marco wrote:

 Hi...
Hi
 
 Can someone help me on this? Actually I can get the dara from the
 system()...But it shows 0 when I print the $result...How can I
 assign the system() to $result ?Thanks...
 
 here below is the code...
 
 $inact = cat /proc/meminfo | grep -w Inactive | sed 's/^.*Inactive: //
 g' | sed 's/kB//';
 $result = system(cat /proc/meminfo | grep -w Inactive | sed 's/
 ^.*Inactive: //g' | sed 's/kB//');
 print $result;

I hesitateI'm sure all the cat/grep/sed can be done in perl. 
There are probably modules that will do exactly what you want...but 
this works for me:


#!/usr/bin/perl

use strict;
use warnings;

# Ensure all the command is on one line or you get a shell error.
my $inact = cat /proc/meminfo | grep -w Inactive | sed 
's/^.*Inactive: // g' | sed 's/kB//';

my $result = system($inact);
print $result;

1256480



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




Re: Hash slice

2007-11-12 Thread Beginner
On 9 Nov 2007 at 20:04, Jenda Krynicky wrote:

 From: Beginner [EMAIL PROTECTED]
  On 9 Nov 2007 at 16:35, Jenda Krynicky wrote:
  
   From: Beginner [EMAIL PROTECTED]
#!/bin/perl

use strict;
use warnings;
use Data::Dumper;

my @keys = qw(fe fi fo thumb);
my @valone = 1..4;
my @valtwo = 10..14;
my %hash;
@[EMAIL PROTECTED] = [EMAIL PROTECTED],@valtwo];
   
   [...] creates an array reference. You want 
   
 @[EMAIL PROTECTED] = ( [EMAIL PROTECTED],[EMAIL PROTECTED]);
   
   Probably. Though it will only set the values for 'fe' and 'fi',
   because I only specify two values.

  
  What I was attempting was to have each key to be assigned the 
  coresponding items from the array. So it might look like something
  like:
  
  $VAR1 = {
  'fe' = [
  1,
  10
 ],
  'fi' = [
  2,
  11,
 ],
  'fo' = [
  3,
  13,
 ],
  'thumb' = [
  4,
  14,
  ]
  };
 
 @[EMAIL PROTECTED] = map [$valone[$_], $valtwo[$_]] (0..$#valone);
 
 
 The map produces a list of arrayrefs, each referenced array contains
 one item from @valone and one from @valtwo. The 0th element of the
 result, the 0th elements of @valone and @valtwo, etc.

Now there you go again with a beautifully simple use of map that does 
exactly what I want (do you need a comma before (0..$#valone)?).

I notice now that I wrote my example wrong. Each array was meant to 
have 4 items in (sorry Rob). So it should have been

my @valone = 1..4;
my @valtwo = 11..14;

There seems to be a bit of confusion over what I was trying to 
achieve. I typed out the output from Dumper I was expecting because I 
was/am not entirely sure what terms to use. The above operation looks 
like a hash slice to me albeit with another operator (map) involved.

Thanx for the help.
Dp.








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




Hash slice

2007-11-09 Thread Beginner
Hi all,

Is it possible to make a hash slice like so

my %hash;
@[EMAIL PROTECTED] = [EMAIL PROTECTED];

My efforts suggest not:

#!/bin/perl

use strict;
use warnings;
use Data::Dumper;

my @keys = qw(fe fi fo thumb);
my @vals = 1..4;
my %hash;
@[EMAIL PROTECTED] = [EMAIL PROTECTED];

print Dumper(\%hash);

$VAR1 = {
  'ARRAY(0x226d54)' = [
 1,
 2,
 3,
 4
   ]
};

Am I missing something or isn't this possible?
TIA.
Dp.


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




Re: Hash slice

2007-11-09 Thread Beginner
On 9 Nov 2007 at 14:59, Rob Dixon wrote:

 Beginner wrote:
  Hi all,
  
  Is it possible to make a hash slice like so

 Hey Dermot

Hi Rob,
 
 It's certainly possible, but I'm not sure why you've taken a reference
 to your key and value arrays. [EMAIL PROTECTED] is a single scalar value, as 
 is
 [EMAIL PROTECTED], so you're creating a single hash element. Perl has had to
 stringify the reference to @keys as Perl hash keys must be strings.
 The hash value is a reference you your @vals array which contains the
 values 1 through 4 as Dumper shows.

I see, scalar used where list expected.

How about this:

#!/bin/perl

use strict;
use warnings;
use Data::Dumper;

my @keys = qw(fe fi fo thumb);
my @valone = 1..4;
my @valtwo = 10..14;
my %hash;
@[EMAIL PROTECTED] = [EMAIL PROTECTED],@valtwo];

print Dumper(\%hash);
$VAR1 = {
  'fo' = undef,
  'fi' = undef,
  'fe' = [
1,
2,
3,
4,
10,
11,
12,
13,
14
  ],
  'thumb' = undef
};

I can't see why you can't create a slice hows values are arrays or 
why all the values are assigned to the first key.

Not a biggy. I can work around it but I'm interested to know.
Thanx,
Dp.




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




Re: Hash slice

2007-11-09 Thread Beginner
On 9 Nov 2007 at 16:35, Jenda Krynicky wrote:

 From: Beginner [EMAIL PROTECTED]
  #!/bin/perl
  
  use strict;
  use warnings;
  use Data::Dumper;
  
  my @keys = qw(fe fi fo thumb);
  my @valone = 1..4;
  my @valtwo = 10..14;
  my %hash;
  @[EMAIL PROTECTED] = [EMAIL PROTECTED],@valtwo];
 
 [...] creates an array reference. You want 
 
   @[EMAIL PROTECTED] = ( [EMAIL PROTECTED],[EMAIL PROTECTED]);
 
 Probably. Though it will only set the values for 'fe' and 'fi', 
 because I only specify two values.
  

What I was attempting was to have each key to be assigned the 
coresponding items from the array. So it might look like something 
like:

$VAR1 = {
'fe' = [
1,
10
   ],
'fi' = [
2,
11,
   ],
'fo' = [
3,
13,
   ],
'thumb' = [
4,
14,
]
};

(yes I typed that by hand) and not 

$VAR1 = {
  'fo' = undef,
  'fi' = [
10,
11,
12,
13,
14
  ],
  'fe' = [
1,
2,
3,
4
  ],
  'thumb' = undef
};


But I see why it's hasn't worked.
Dp,


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




Re: DBI prepare syntax

2007-11-08 Thread Beginner
On 8 Nov 2007 at 8:59, Mike wrote:

 Hi,

 
 #Update override_exclude set th_flag=N to indicate that thesaurus entries
 #have been added to sierra2_thesaurus.xml
 
 use DBI;
 my $dbh = DBI-connect(dbi:mysql:endeca_tracking,$user,$password);
 my $sth = $dbh-prepare('update override_exclude set th_flag=N 
 where pid=$pid') or die Couldn't prepare statement .$dbh-errstr;
 $sth-execute;

I'm no guru but shouldn't you be double quoting the prepare 
statement:

my $sth = $dbh-prepare(update override_exclude set th_flag='N' 
where pid=$pid)

or better still

my $sth = $dbh-prepare('update override_exclude set th_flag=N 
where pid=?)
$sth-execute($pid);

HTH,
Dp.


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




Re: FileHandle

2007-11-01 Thread Beginner
On 1 Nov 2007 at 19:20, Kaushal Shriyan wrote:

 Hi
 
 I am using FileHandle, Below is my code
 
 
 #!/usr/bin/perl
 
 use warnings;
 use strict;
 
 open(LOGFILE, messages)
 || warn Could not open messages;
 open(DATA, /tmp/data) || die Could not create /tmp/data\n.
 
 while (LOGFILE) {
 print $_\n if /MARK/;
 }
 ###
 
 I am getting syntax error
 
 I know i am doing wrong, please let me know whats causing the issue.

Did the error give a line number? I think it's the lack of brackets 
on the if clause.

 while (LOGFILE) {
 print $_\n if ( /MARK/ );
 }

Hope I'm not too far off.
Dp.


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




Re: FileHandle

2007-11-01 Thread Beginner
On 1 Nov 2007 at 19:43, Kaushal Shriyan wrote:

 Thanks Rob
 
 Its working Fine, Now when I am using the below code to write something to
 file messages
 the below code is not writing the text write some text  to the file
 messages.
 
 ##
 #!/usr/bin/perl
 
 use strict;
 use warnings;
 
 open(LOGFILE, messages)
 || warn Could not open messages.\n;
 open(DATA, /tmp/data) || die Could not create /tmp/data\n.;
 
 print LOGFILE write some text ;
 
 ##
 
 when i do a less messages, i see there is no text write some text at the
 end of the file.
 
 what I am doing wrong.

Trying to redeem myself!

You have opened LOGFILE as readonly and then printed to it. I would 
have expected an error message about this. I think you want:

print DATA write some text;

Dp.
 



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




impatient DBI query

2007-10-31 Thread Beginner
Hi,

I have ordered my Perl DBI book (is that a leopard?) but I am 
impatient and want to know how I could do a select/like statement a 
bit like this:

SELECT foo FROM bar WHERE foo like 'baz%' 

the % being the wildcard operator.

Any advice?
Dp.


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




Re: impatient DBI query

2007-10-31 Thread Beginner

On 31 Oct 2007 at 0:00, Jeff Pang wrote:

 
 
 -Original Message-
 From: Beginner [EMAIL PROTECTED]
 Sent: Oct 31, 2007 9:20 PM
 To: beginners@perl.org, beginners@perl.org
 Subject: impatient DBI query
 
 Hi,
 
...snip
 
 try something like this:
 
 my $dbh = DBI-connect(...);
 my $str = 'select foo from bar where foo like ?';
 my $sth = $dbh-prepare($str);
 $sth-execute('baz%') or die $dbh-errstr;
 my @results = $sth-fetchrow_array;
 $sth-finish;

Of course. Put it into execute. Thanx Jeff.
Dp.


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




Quotes and apostrophes assistance

2007-10-29 Thread Beginner
Hi,

I am trying to insert a lots file paths into an SQLite table and am 
having trouble with filenames with apostrophes in.

Below is the snippet I have been using. I have experimented with 
sprintf,  qq and a combination of both but can't get a quoting system 
that will get DBI to accept paths like q(/path/to/Camellia japonica 
'Mercury'2.tif).

I don't want to transform the path. I want to maintain the true path 
without having to do substitiutions everytime the data gets read from 
or inserted into the table. It would be a maintenance headache 
otherwise.

Is there a technique for this anyone or any advice anyone can offer 
(apart from shooting the users how uploaded the files in the first 
place).

TIA,
Dp.

sub Check_if_exists {
 my $name = shift;
 my $str = qq($name);
 my $statement = sprintf(SELECT id FROM files where 
path='%s',$str);
# my $statement = qq(SELECT id FROM files where path=$str);
 my $rows = $dbh-selectrow_array($statement) or die Can't 
selectrow_array statement=$statement: ,$DBI::errstr,\n;
 return $rows;
}


DBD::SQLite::db selectrow_array failed: near Mercury: syntax 
error(1) at dbdimp.c line 271 at myfile.pm line 158.
Can't selectrow_array statement=SELECT id FROM images where 
tiffpath='/data/finished/GB 10484/Camellia japonica 
'Mercury'2.NEF.tif': near Mercury: syntax error(1) at dbdimp.c line 
271


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




Re: array within array

2007-10-29 Thread Beginner
On 29 Oct 2007 at 8:42, Mike Tran wrote:

 Hey all,
 
  
 
 I'm new with Perl and need help with this simple script. I'm still
 playing around with the script below to get a feel for Perl. My script
 below is incomplete and I'm doing an array within an array which is
 incorrect. Please help.  
 
  
 
 Here's what I want to do; I have to flat files (pipe delimited, export
 from a database) that I want to parse through and assign variables for
 each column. Basically, I want to parse through exclude_bases.txt and
 do: if base_no in exclude_bases.txt equals to base_no in base.txt then
 search in the description field of base.txt for the string listed in
 the keyword field in exclude_bases.tx and replace with new_keyword
 in exclude_bases.txt and write the out put into a new file called
 new_bases.txt.
 
  
 
 Any suggestions on how I could accomplish the above task is greatly
 appreciated. Thanks all. 
 
  
 
 Flat Files:
 
  
 
 base.txt:
 
 base_no|name|description
 
 1|test|test desc
 
 10001|test2|test desc 2
 
 10002|test3|test desc 3
 
  
 
 exclude_bases.txt:
 
 base_no|keyword|new_keyword|
 
 1|test desc|testdesc|0
 
 10001|test desc 2|testdesc2|0
 
 10002|test desc 3|testdesc3|1
 
  
 
  
 
  
 
 #!/usr/bin/perl
 
  
 
 use strict;
 
 use warnings;
 
  
 
 my $exclude_bases = exclude_bases.txt;
 
 my $current_base = base.txt;
 
 my $output = new_bases.txt;
 
  
 
 my %exclude_bases;
 
 my $exclude_text;
 
 my $exbase_no;
 
 my $keyword;
 
 my $new_keyword;
 
  
 
 open(EXCLUDE,exclude_bases.txt )|| die(Could not open file!);
 
 %exclude_bases=EXCLUDE;
 
 close(EXCLUDE);
 
  
 
 my $base_no =;
 
 my $name=;
 
 my $description=;
 
 my $current_base=;
 
 my $base_text=;
 
 my %bases;
 
  
 
 open(BASE,base.txt)|| die(Could not open file!);
 
 %bases=BASE;
 
 close(BASE);
 
  
 
 #choping lines and assign variables to base.txt
 
 foreach $base_text (%bases)
 
 {
 
   chop($base_text);
 
   ($base_no,$name,$description)=split(/\|/,$base_text);
 
  
 
 #choping lines and assign variables to exclude_bases.txt
 
 foreach $exclude_text (%exclude_bases)
 
 {
 
   chop($exclude_text);
 
   ($exbase_no,$keyword,$new_keyword)=split(/\|/,$base_text);
 
   
 
   if ($exbase_no=$base_no) {
 
   $keyword =~ s/$keyword/$new_keyword/g;}
 

Well here my effort. It should help you get closer to what your after 
but it's not complete. I would use hashes not arrays, you'll find 
them extremely useful for de-duping data 

I haven't run the script below, please do a perl -c first. 

Check out exists

perldoc -f exists



#!/usr/bin/perl

use strict; # Well done
use warnings; # ditto.

my $exclude_bases = exclude_bases.txt;
 
open(EXCLUDE,excludes.txt )|| die(Could not open file!);
while (EXCLUDE) {
chomp;
my @fields = split(/|/,$_);
$exclude_bases{$F[0]} = 0; # $f[0] contains base_no
}
close(EXCLUDE);

open(BASE,base.txt)|| die(Could not open file!);
while (BASE) {
chomp;
my @fields = split(/|/,$_);
if (! exists($exlude_bases{$_}) ) {
print $f[2]\n;
}
}
close(BASE);


HTH,
Dp.



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




Re: Quotes and apostrophes assistance

2007-10-29 Thread Beginner
On 29 Oct 2007 at 10:55, Paul Lalli wrote:

 On Oct 29, 12:31 pm, [EMAIL PROTECTED] (Dr.Ruud) wrote:
  Beginner schreef:
 
   I am trying to insert a lots file paths into an SQLite table and am
   having trouble with filenames with apostrophes in.
 
  Use placeholders,
 
 Good advice.
 
  so prepare/execute.
 
 irrelevant advice, nothing to do with the problem at hand.  There is
 no reason to alter the OP's method of using selectrow_array.
 
 my ($val) = $dbh-selectrow_array(SELECT foo FROM bar WHERE id = ?,
 undef, q{stuff'with'quotes'});
 
 http://search.cpan.org/~timb/DBI-1.601/DBI.pm#selectrow_array
 
Being new to DBI (and not much of expert in perl anyway) so I can't 
add much to the debate. 

What I can say is that this always dies

my $statement = sprintf(SELECT foo FROM bar where path=%s,$dbh-
quote($name));
my $rows = $dbh-selectrow_array($statement) or 
die Can't selectrow_array statement=$statement: ,$DBI::errstr, 
NO:,$DBI::err,$DBI::state\n;


or this:

my ($rows) = $dbh-selectrow_array(SELECT foo FROM bar where 
path=?,undef,q($name)) or die snip


whereas if I am do 

my $statement = sprintf(SELECT foo FROM bar where path=%s,
$dbh-quote($name));
my $sth = $dbh-prepare($statement) or 
die PREPARE:statement=$statement: ,$DBI::errstr,\n;
 $sth-execute or die EXECUTE: statement=$statement: 
,$DBI::errstr, NO:,$DBI::err,\n;
 my @rows;
 while (defined(my $i = $sth-fetchrow_array)) {
push(@rows,$i);
 }


It will process. What I want is to check if a fully qualified file 
path exists before attempting to insert a new record so I opted for 
the shorthand notation.

I didn't understand the 2 argument list in Paul's selectrow_array 
either.

I am currently fighting with 
$dbh-last_insert_id(undef,undef,undef,undef)

which constantly returns 0 so I can't get any further with my 
original query except to say the first one always returns a code to 
indicate a problem whereas the more verbose latter method will work.

BTW: SQLite 3.5.1 
DBI: 1.6.1.

Any further advice appreciated.
Dp.


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




Re: error in qx

2007-10-26 Thread Beginner
On 26 Oct 2007 at 19:14, Jeff Pang wrote:

 On 10/26/07, Sayed, Irfan (Irfan) [EMAIL PROTECTED] wrote:
  Hi All,
 
  I am executing my $usr=qx(who am i); to get the user id on unix
  machine but it is giving error. sh: who am i: not found
 
 
 Oops,it's `whoami` not `who am i` unless you have aliased it.

I don't know:

-bash-3.00$ who am i
dpaikkos pts/14   Oct 26 12:16 (host.mydomain.com)

Work for me on a bash shell as does whoami.
Dp.



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




modify mirror list - CPAN

2007-10-24 Thread Beginner
Hi,

I want to modify the mirror list that I selected when I did a first 
run of perl -MCPAN.

One of the mirror I choose has stopped being a mirror and causing the 
the install process to take much longer. I did perl -MCPAN -e shell 
but there were no options that looked relevant.

Is there a way to issue a command to redo the config. I could remove 
the whole of .cpan but that seems drastic.

Thanx,
Dp.


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




Help generating XML output

2007-10-23 Thread Beginner
Hi,

I have been trying to output XML that looks like this:

users
username id=10dermot/username
username id=17joe/username
...
/users

I have tried XML::Simple and XML::Generator but keep hitting the same 
problem when it comes to separating the id attribute and the value 
from my hash reference.

$VAR1 = {
   'dermot' = '10',
   'joe' = '17',
   'rose' = '11',
   'phil' = '13',
   'brian' = '20',
   'andy' = '15',
 };

If I use this loop to generate the output with XML::Generator I only 
get the last user in the XML

my $xml;
my $gen = XML::Generator-new(':pretty');
foreach my $k (keys %{$ref}) {
   $xml = $gen-users(
  $gen-username({ id = $ref-{$k}},$k),
   );
   }
print $xml;

username id=15andy/username

With XML::Simple I considered using this:
 
my $xml = XMLout($ref, RootName = 'users', ValueAttr = { '??' = 
'??'}

But I can't determine how to use ValueAttr to suit my needs as the 
keys/values are not know.

I think XML::Generator would suit me best but I can't see can append 
data to $xml. Can anyone offer any advice?

TIA,
Dp.




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




Re: Help generating XML output

2007-10-23 Thread Beginner
On 23 Oct 2007 at 12:12, Rob Coops wrote:

 foreach my $k (keys %{$ref}) {
   $xml = $gen-users( # $xml gets over written with every new
 key So instead of doing that I would try $xml .= (appending)
  $gen-username({ id = $ref-{$k}},$k),
   );
   }
 

Perhaps I should have mentioned that I had tried that and the result 
is empty XML like this


my $gen = XML::Generator-new(':pretty');
my $xml;
foreach my $k (keys %{$ref}) {
 $xml .= $gen-users(
$gen-username({ id = $ref-{$k}},$k),
);
 }

/usersusers


This seems to work but my browser is complaining about the output:
XML Parsing Error: junk after document element
The source looks out but there is no root level element.

my $xml;
foreach my $k (keys %{$ref}) {
 $xml .= $gen-username({ id = $ref-{$k}},$k);
  }
print $xml;


So it's close but not quite there.
Dp.


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




Re: Help generating XML output

2007-10-23 Thread Beginner
On 23 Oct 2007 at 14:21, Jenda Krynicky wrote:

 From: Rob Dixon [EMAIL PROTECTED]
  I am unfamiliar with XML::Generator, but have experimented with it
 for
  the purposes of your question and it seems to be essentially a
 translator
  that will convert a Perl fragment into an XML fragment, and I can
 see no
  way to modify existing XML. Because of this it seems extremely
 limited in
  its application, as you would have to write
  
my $xml = $gen-users(
  $gen-user({id = 10}, 'dermot'),
  $gen-user({id = 17}, 'joe'),
:
);
  
  to create your desired output, which simply moves your problem to
 one of
  how to generate the Perl from your data in the first place. If
 someone
  on the list is familiar with XML::Generator then please correct me
 if I
  am wrong.
 
 It's just a matter of one map():
 
 #!perl
 use XML::Generator;
 
 $ref = {
   'dermot' = '10',
   'joe' = '17',
   'rose' = '11',
   'phil' = '13',
   'brian' = '20',
   'andy' = '15',
 };
 
 my $gen = XML::Generator-new(':pretty');
 my $xml = $gen-users(
  map { $gen-user({id = $ref-{$_}}, $_) } keys %{$ref}
 );
 
 print $xml;
 __END__

Well that certainly does it. I could almost kick myself for not 
seeing it.

On a more general point I haven't found it easy to find modules that 
output XML or perhaps I should say, I didn't find the ones I did look 
at to be well documented in terms of examples or show the variety of 
different ways data structures can be represented in XML.

Excuse my whinge. Thanx to you both your help.
Dp.


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




Re: Help generating XML output

2007-10-23 Thread Beginner
On 23 Oct 2007 at 16:46, Jenda Krynicky wrote:

 From: Beginner [EMAIL PROTECTED]
  On a more general point I haven't found it easy to find modules
 that 
  output XML or perhaps I should say, I didn't find the ones I did
 look 
  at to be well documented in terms of examples or show the variety
 of 
  different ways data structures can be represented in XML.
 
 Well, as the author of one of the modules you may have looked at I
 am 
 to blame. 

Opps. The words foot and mouth spring to mind. No offence 
intended, honest.
Dp.


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




Re: code ref within a hash?

2007-10-19 Thread Beginner
On 19 Oct 2007 at 15:29, Beginner wrote:

 On 19 Oct 2007 at 9:26, Stephen Kratzer wrote:
 
  On Friday 19 October 2007 07:41:40 Beginner wrote:


...snip
 so I modify the hash so it looks like:
   ...snip
   'name'  = edit_from_path($File::Find::name),

I guess I should write that as simply

'name'  = edit_from_path($File::Find::name),

Dp.


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




code ref within a hash?

2007-10-19 Thread Beginner
Hi,

In the script below I am trying my hand at using a code ref within a 
hash. I want the key 'name' to contain a scalar value. It does but I 
am not sure how to dereference it.

Here is the output from the script at the moment.

/data/users/nat/finished/01.tif SCALAR(0x8db3cac)
/data/users/nat/finished/19.tif SCALAR(0x8db3cf4)
/data/users/nat/finished/06.tif SCALAR(0x8db3d3c)

If i assign the return from the subroutine before, putting into a 
scalar and using that value within the hash then it's fine but in 
it's current state I get the SCALAR(0x8db3d3c) from $f-{'name'}

Can anyone offer me some advise?
Thanx,
Dp.


=script===
#!/usr/bin/perl

use lib qw(.);
use strict;
use warnings;
use Config;
use File::Find;

my @list_of_found;

find(\wanted, $sroot);


foreach my $f (@list_of_found) {
print $f-{'basename'}, ,$f-{'name'},\n;
}


sub wanted {

 if ($File::Find::name =~ /users/  $_ =~ /\.tif$/) {

my %file = (
'tiffpath'  = $File::Find::name,
'basename'  = $_,
'name'  = \edit_from_path($File::Find::name),
);
push(@list_of_found,\%file);

 }

}

sub edit_from_path {
 (my $n) = ($_ =~ /users\/(\w+)\//); 
 return $n;
}
===

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




Re: Storing a subroutine pointer inside a variable?

2007-10-09 Thread Beginner
On 9 Oct 2007 at 9:01, Jeff Pang wrote:

 2007/10/9, yitzle [EMAIL PROTECTED]:

 sub test {
  my ($function, $description, $var, undef) = @_;
  print $description . : ;
  print $function-($var) ? Yes\n : No\n;
 }

Can someone explain why there is a 4th, undefined variable being 
declared in test? It appears to work it too.

sub test {
 my ($function, $description, $var) = @_
...

I'm sure there is a reason for it but I can't see it.
Thanx,
Dp.



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




Re: Hash receive Array

2007-10-09 Thread Beginner
On 9 Oct 2007 at 11:09, Rodrigo Tavares wrote:

Hi

 Hello,
 
 I created a hash with some elements and keys.
 The hash must receive a array.
 
 Can I do it ?   

yes. I think this will work.

$hash{'myarray'} = [1, 2, 3]; 

or 

$hash{'myarray'} = [EMAIL PROTECTED];

and I am sure there are lots of other ways to do it too.
HTH,
Dp

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




Variable scope

2007-10-02 Thread Beginner
Hi,

I thought that the code snip below should work but I am not getting 
my text into the the file. The file is created but it's empty.

Ideally I want to create the log file outside any sub routines so 
that $log to be available to any sub I have created and hence not 
scoped to any one sub routine.  

Is my understanding not correct here? Should I be doing this in 
another way?

Thanx,
Dp.



#!/bin/perl

package Images;

 use strict;
 use warnings;
 use vars qw($log);

 $| = 1;
 our $log;
 my $logpath = 'mylog.txt';
 open($log,$logpath) or die Can't append to $logpath: $!\n;


sub mysub {

my $var = 'Hello';
print $log Starting mysub with val\n;

}

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




Re: Variable scope

2007-10-02 Thread Beginner
On 2 Oct 2007 at 15:23, Rob Dixon wrote:

 Hi Dermot. You're a little confused, but you're not far out!

Your being kind. 

  
   $| = 1;

I wasn't aware this only applied to STDOUT. My log messages all 
appear at once, when the script has exited and I was hoping for some 
'realtime' messages.

 No need to autoflush.
 
   our $log;
 
 There is no need to declare the $log variable with 'our' here (or to
 'use vars' above): a 'my' variable will do the job fine.

Noted. I can have a package variable.


   my $logpath = 'mylog.txt';
   open($log,$logpath) or die Can't append to $logpath: $!\n;
 
 open my $log, '', $logpath or die Can't append to $logpath: $!;
 
 mysub();

The killer.

 
 HTH,

Sure did. Sorry for not spending a bit longer experimenting before I 
sent the mail.
Dp.


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




Re: Text::Aspell

2007-09-14 Thread Beginner
On 11 Sep 2007 at 12:38, Chas Owens wrote:

 On 9/11/07, Beginner [EMAIL PROTECTED] wrote:
 snip
 I think my installation might be broken some how.
 Would
  you agree?
 snip
 
 At this point, yes, there is something other than the Perl code
 you/I
 wrote that is at fault.  My versions are Aspell 0.60.4-4 and


Cracked it, well sort of. My OS came with Aspell 0.50 installed via 
the package manager and I had install v60.4 as well. I removed 
everything and started again installed via the package manager. This 
unfortunately has left me with a slightly old version but it works.

Thanx for the help Chas and all.
Dp.





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




Re: Help with data returned by regex match

2007-09-11 Thread Beginner
On 11 Sep 2007 at 11:36, kapil.V wrote:

 Hi,
 
 #!/usr/bin/perl -w
 my $path = shift;
 my $machine = shift;
 my (undef,$country, $property) = split /\//,$path;
 my $xmlData = qx!./pindown. php $machine!;
 my @contacts = $xmlData =~ /property name=\$property\  
 country=\$country\ .+?contact type=\admin\ .+?\/contact /is;
 #print $\n;
 print @contacts;
 
 This prints 1
 But printing $ prints a block of XML.
 Why does the array contacts not contain the pattern matched?(Also tried 
 assigning the matched pattern to a scalar.)

1 is the number of times it made a match. I am not sure about 
capturing patterns into arrays.

I would have tried to capture the string like this:

(my $match) = ($xmlData =~ /property name=\$property\  
 country=\$country\ .+?contact type=\admin\ .+?\/contact 
/is);

No sure if it's the most efficient way though and I am not sure if 
that's exactly what your trying to do.
HTH,
Dp.



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




Re: Text::Aspell

2007-09-11 Thread Beginner
On 11 Sep 2007 at 9:25, Chas Owens wrote:

 On 9/11/07, Dermot Paikkos [EMAIL PROTECTED] wrote:
  On 10 Sep 2007 at 12:52, Chas Owens wrote:

..snip 
 Three things:
 1. You are building dict.local, but the error message says local.dict
 2. Did you try my example and did it work?
 3. You aren't really running as root are you?

1) That was a typo in the mail  but I redid it to be sure
cat wordlist
aardvark
abandonment
Aberystwyth
 aspell --lang=en create master ./local.dict  wordlist
perl spellchecker.pl 

String=local.dict
Aberystwyth not found!
Use of uninitialized value in print at spellcheck.pl line 40.
Check returned
The file /root/aspell/local.dict is not in the proper format

2) I believe I have followed what you did in your reply before and 
above. To be sure i pasted you script in a file, renamed 
'./dict.local' to ./local.dict. Ran it and got this:
Use of uninitialized value in array element at chas.pl line 19.
Aberystwyth not found
Use of uninitialized value in array element at chas.pl line 19.
Perl not found
Use of uninitialized value in array element at chas.pl line 19.
FOO not found
Use of uninitialized value in array element at chas.pl line 19.
bar not found
Use of uninitialized value in array element at chas.pl line 19.
abcdfooblahsmack not found

I then added the $speller-errstr to the last line and I get:
...
Use of uninitialized value in array element at chas.pl line 19.
abcdfooblahsmack not found
The file ./local.dict is not in the proper format

3) Oh Oui :-\

Dp.



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




Re: Text::Aspell

2007-09-11 Thread Beginner
On 11 Sep 2007 at 10:04, Chas Owens wrote:

 On 9/11/07, Beginner [EMAIL PROTECTED] wrote:
 snip

 Please do not type error messages.  Copy and paste them instead.
 Actually the rule should be, don't type anything but your
 commentary.
 
 snip

 mkdir temp
 cd temp
 echo Aberystwyth  words
 echo Perl  words
 echo FOO  words
 echo abcdfooblahsmack  words
 aspell --lang=en create master ./dict.local  words
 
 then create the perl script I mentioned in a previous email and try to
 run it, and this is the important part, in the directory you just
 created.

-bash-3.00$ mkdir temp 
-bash-3.00$ cd temp
-bash-3.00$ echo Aberystwyth  words 
-bash-3.00$ echo Perl  words 
-bash-3.00$ echo FOO  words
-bash-3.00$ echo abcdfooblahsmack  words 
-bash-3.00$ aspell --lang=en create master ./dict.local  words  
-bash-3.00$vi chas.pl
...snip

-bash-3.00$ perl chas.pl
Use of uninitialized value in array element at chas.pl line 18.
Aberystwyth not found
Use of uninitialized value in array element at chas.pl line 18.
Perl not found
Use of uninitialized value in array element at chas.pl line 18.
FOO not found
Use of uninitialized value in array element at chas.pl line 18.
bar not found
Use of uninitialized value in array element at chas.pl line 18.
abcdfooblahsmack not found


 snip
  3) Oh Oui :-\
 snip
  It isn't a question of if you will
 accidentally wound yourself, but more of when are you going to kill
 yourself.

All done under my mortal login. 

-bash-3.00$ find /usr/lib/perl5 -name Aspell* -ls

4096 Jul  6 19:20 /usr/lib/perl5/site_perl/5.8.6/i386-linux-thread-
multi/auto/Text/Aspell
93685 Jul  6 19:20 /usr/lib/perl5/site_perl/5.8.6/i386-linux-thread-
multi/auto/Text/Aspell/Aspell.so
0 Jul  6 19:20 /usr/lib/perl5/site_perl/5.8.6/i386-linux-thread-
multi/auto/Text/Aspell/Aspell.bs
11139 May  3 05:59 /usr/lib/perl5/site_perl/5.8.6/i386-linux-thread-
multi/Text/Aspell.pm

My version of Aspell is 0.60.5. My version of Text::Aspell is 0.08.

I believe I am doing everything that the docs ask and you have 
suggested. I think my installation might be broken some how. Would 
you agree?

Thanx,
Dp.



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




Text::Aspell

2007-09-10 Thread Beginner
Hi,

I am sorry if this is a bit module specific, I am hoping someone on 
the list has some experience of Text::Aspell and can help.

I am trying to use a custom dictionary. I can use the command line

aspell check --master=./dict.local somefile 

and words included in my dictionary like Aberystwyth are not 
flagged as unknown.

With the following script:
 
=== spellcheck.pl 
use strict;
use warnings;
use Text::Aspell;

my $word = Aberystwyth;

my $speller = Text::Aspell-new;
die unless $speller;

$speller-set_option('master' , './dict.local');

my $string = $speller-get_option('master');
print $speller-errstr,\n;
print String=$string\n;


print $speller-check( $word )
  ? $word found\n
  : $word not found!\n;


Outputs:

String=./spl-dict
Aberystwyth not found!


The script is a almost complete paste from the help docs for 
Text::Aspell. I have tried other options (personal|size) from the 
GNU/Aspell but they all seem to be ignored. 

Does anyone have any ideas why this isn't working? Could this be due 
to an environment variable? 

Any ideas appreciated. Thanx,
Dp.






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




Re: Test data generation using Perl Scripting.

2007-09-07 Thread Beginner
On 7 Sep 2007 at 9:47, Chas Owens wrote:

 On 9/7/07, Chas Owens [EMAIL PROTECTED] wrote:
 snip
  #FIXME: this creates invalid dates like 2007-02-30
  sub rand_date {
  sprintf %04d-%02d-%02d,
  2000 + int rand 7,
  1 + int rand 12,
  1 + int rand 31;
  }
 snip
 
 Actually that sub can't return 2007-02-30, kudos to anyone else who
 can spot why.

No return statement?



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




Re: Regex help

2007-09-04 Thread Beginner
On 3 Sep 2007 at 17:44, Rob Dixon wrote:

 Beginner wrote:
  
  I am trying to come up with a regex to squash multiple commas into
  one. The line I am working on looks like this:
  
  SPEED OF LIGHT, ,  LIGHT SPEED,TRAVEL,TRAVELLING, ,  
  DANGER,DANGEROUS,PHYSICAL, ,  CONCEPT,CONCEPTS, , , , , , , , , ,
  
  There are instances of /,\s{1,},/ and /,,/ 
  
  The bit that I am struggling with is finding a way to get a use a
  multiplier for the regex /,\s+/ but I have to be careful not to 
  remove single entries. I guess the order of my substitutions is 
  important here.
  
  Can anyone offer any tips please?
 
 Hey Dermot.
 
 I think just
 
   $text =~ s/,[,\s]+/,/g;
 
Indeed Rob that works too. 

You've used square brackets for what I think they call 'alternation'; 
the next character might be a comma and a whitespace. I have always 
thought of square brackets as being for character classes EG: [a-z]. 
I associate alternation with parenthesis and the pipe /(this|that)/

perlrequick demos examples like:

/[a-z]+\s+\d*/;  # match a lowercase word, at least some space, and
 # any number of digits

but I don't think I've seen examples where there is a character class 
like \s or \w within square brackets before. 

Anyway back to reading perlretut, perlop and others.
Thanx,
Dp.



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




Re: how to remove ^M character from every line

2007-09-03 Thread Beginner
On 3 Sep 2007 at 17:26, divya wrote:
 
 A file generated on Windows machine is used on linux m/c while scripting.
 A sample line from the file is as shown:
 
 //---^M
 File name : project_name^M
 .
 
 Now in the perl script how can I remove ^M without running the command 
 dos2unix.
 
 Note: Trying to split the line whenever ^ detected is not working.
 
 Looking forward for your response.

I use s/\s+$//;

Dp.
 

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




RE: how to remove ^M character from every line

2007-09-03 Thread Beginner
On 3 Sep 2007 at 13:38, Andrew Curry wrote:

 The problem is its unclear, its always better to be clear in code. It will
 also remove any formatting from the end of lines. If you wanted to be just
 as crude you can use chomp. 

I paritally agree that it could be un-clear. Perhaps 

s/\s+$//;   # Remove all \r, \n, ^M from end of line

would be clearer. 

I got this solution from this list because I suffered from this same 
problem a lot and chomp was not working as expected. It would leave a 
character on the end that still interpreted as a newline by the 
shell. When that happened, in the context of a file-system lookup, 
the results were baffling. 

Dp.




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




Regex help

2007-09-03 Thread Beginner
Hi,

I am trying to come up with a regex to squash multiple commas into 
one. The line I am working on looks like this:

SPEED OF LIGHT, ,  LIGHT SPEED,TRAVEL,TRAVELLING, ,  
DANGER,DANGEROUS,PHYSICAL, ,  CONCEPT,CONCEPTS, , , , , , , , , , 

There are instances of /,\s{1,},/ and /,,/ 

The bit that I am struggling with is finding a way to get a use a 
multiplier for the regex /,\s+/ but I have to be careful not to 
remove single entries. I guess the order of my substitutions is 
important here.

Can anyone offer any tips please?
Dp.


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




RE: Regex help

2007-09-03 Thread Beginner
On 3 Sep 2007 at 16:15, Andrew Curry wrote:

 Think
 
 s/(\,+\s*)+/,/g;
 
 Should work
 
 It produces
 SPEED OF LIGHT,LIGHT
 SPEED,TRAVEL,TRAVELLING,DANGER,DANGEROUS,PHYSICAL,CONCEPT,CONCEPTS
 
 If that's what you want. 

Exactly what I want. Thanx,
Dp.




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




RE: Regex help

2007-09-03 Thread Beginner
On 3 Sep 2007 at 16:12, Andrew Curry wrote:

 $ perl -le'
 $_ = q[SPEED OF LIGHT, ,  LIGHT SPEED,TRAVEL,TRAVELLING, ,
 DANGER,DANGEROUS,PHYSICAL, ,  CONCEPT,CONCEPTS, , , , , , , , , , ];  
 print; s/,\s*(?=,)//g; print; '
 SPEED OF LIGHT, ,  LIGHT SPEED,TRAVEL,TRAVELLING, ,
 DANGER,DANGEROUS,PHYSICAL, ,  CONCEPT,CONCEPTS, , , , , , , , , , SPEED OF
 LIGHT,  LIGHT SPEED,TRAVEL,TRAVELLING,  DANGER,DANGEROUS,PHYSICAL,
 CONCEPT,CONCEPTS,
 
 
 $ perl -le'
 $_ = q[SPEED OF LIGHT, ,  LIGHT SPEED,TRAVEL,TRAVELLING, ,
 DANGER,DANGEROUS,PHYSICAL, ,  CONCEPT,CONCEPTS, , , , , , , , , , ]; print;
 $_ = join ,, grep /\S/, split /,/; print; '
 SPEED OF LIGHT, ,  LIGHT SPEED,TRAVEL,TRAVELLING, ,
 DANGER,DANGEROUS,PHYSICAL, ,  CONCEPT,CONCEPTS, , , , , , , , , , SPEED OF
 LIGHT,  LIGHT SPEED,TRAVEL,TRAVELLING,  DANGER,DANGEROUS,PHYSICAL,
 CONCEPT,CONCEPTS
 
 
 
 
 John

Okay I need to ask what's going on here.  

I had to use the  

s/,\s*(?=,)//g  

expression because the  

s/(\,+\s*)+/,/g;  

regex in my code snip wasn't working as it did on the text snippet I 
originally supplied.  

=== code snip ===
 while (FH) { 
chomp($_);  
s///g; 
s/\t/, /g;  
s/,\s*(?=,)//g; 
print \$_\\n; 
}
 == 

I can understand the 2nd method: A grouped, literal comma (\,), one 
or more times followed by a zero or more spaces.  

The 2nd regex reads to me like, a comma then zero or more spaces but 
what's that (?=,) doing? Is it referring to the preceding expression 
and saying if it matches up to 1 time? I can't see what the equal 
sign is doing either.

Enlightment please.
Dp.


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




Logging STDERR and other output

2007-08-30 Thread Beginner
Hi,

I want all the output plus any error messages to got to a log file. I 
used the BEGIN block to direct STDERR into the file:

BEGIN { 
  open(STDERR, /usr/local/myreports/report.log) || die Can't 
write to file: $!\n;
}

use strict; 
use warnings;
...
### Start some logging ###
my $log;
my $logfile = $dist_dir/report.log;
open($log,$logfile) || die Can't write to $logfile: $!\n;
print $log $0 called at , tm, with pid $$\n;


I am not massively happy with this method. I can't seem to use a 
scalar that I can share with the rest of the script for the log file 
and if I do a perl -c myscript.pl, all the messages go to the log 
file.

Q1) Can I use a scalar instead of having to give the full file path 
in the BEGIN block? I haven't tried it but I suspect is would be fall 
within the scope of the BEGIN block and as far as I know, you cannot 
declare anything before a BEGIN block. Failing that, can anyone 
suggest a different way of doing this.

Q2) You sometimes see scripts accept the verbose/debug command line 
argument. How can you implement a system so that you can ask for more 
messages? Once you've set $debug = 1; do you have to pepper your 
script with 

print $log some message\n if $debug == 1;

TIA,
Dp.





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




Re: Logging STDERR and other output

2007-08-30 Thread Beginner
On 30 Aug 2007 at 6:32, Peter Scott wrote:

 On Thu, 30 Aug 2007 10:32:01 +0100, Beginner wrote:
  I want all the output plus any error messages to got to a log file. I 
  used the BEGIN block to direct STDERR into the file:
  
  BEGIN { 
open(STDERR, /usr/local/myreports/report.log) || die Can't 
  write to file: $!\n;
  }
  
  use strict; 
  use warnings;
  ...
  ### Start some logging ###
  my $log;
  my $logfile = $dist_dir/report.log;
  open($log,$logfile) || die Can't write to $logfile: $!\n;
  print $log $0 called at , tm, with pid $$\n;
 
 Why are you using a BEGIN block?  Why not just make it the first
 executable statement?  Do you have any other 'use' statements in the
 program?

Yes I do. Several standard modules plus one or 2 of my own. The BEGIN 
block adds the path to my modules as well so it really looks like 
this at the moment (I have tested Mumia's INIT yet):

BEGIN { unshift @INC, '/etc/perl';
$| = 1;
open(STDERR, /usr/local/myreports/report.log) || die 
Can't write to file: $!\n;
}

use MY::MakePDF;
use MY::SendEmail;
use MY::Number;
use MY::PDF_Handler;
use File::Basename;
use strict;
use warnings;

I want the STDERR from those modules to go to the log file also.


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




Re: Logging STDERR and other output

2007-08-30 Thread Beginner
On 30 Aug 2007 at 10:59, Adriano Ferreira wrote:

 On 8/30/07, Beginner wrote:

 
  BEGIN { unshift @INC, '/etc/perl';
 
 This is better done with
 
 use lib qw(/etc/perl);

use lib ('/etc/perl');

Well that seems to work :-).

 which doesn't need the surrounding BEGIN block.
 
  $| = 1;
  open(STDERR, /usr/local/myreports/report.log) || die
  Can't write to file: $!\n;
  }
 
  use MY::MakePDF;
  use MY::SendEmail;
  use MY::Number;
  use MY::PDF_Handler;
  use File::Basename;
  use strict;
  use warnings;
 
  I want the STDERR from those modules to go to the log file also.

my $dist_dir = '/usr/local/myreports'; 
our $logfile = $dist_dir/report.log;  

INIT { open(STDERR, $logfile) || die Can't write to file: $!\n; 
}  


I tried the INIT option and that worked also and I liked the fact 
that my `perl -c myscript.pl` sent it's output to screen and not my 
log file and I can use a scalar for logfile. 

q1) Does this still give me the effect of getting any errors from the 
other modules directed to our $logfile?

q2) Will our $logfile now be a shared variable across all my modules?

q3) The $debug/verbose question: Will I have to pass subroutines in 
other modules the $debug value if I am going to ask for more output, 
or if I do the same to $debug as I did with $logfile, use our instead 
of my. Will that allow those subroutines to check if debug is 
enabled?

Sorry seem to have added more questions somehow?
Dp.


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




Re: marine subroutine

2007-08-30 Thread Beginner
On 30 Aug 2007 at 1:18, anders wrote:

 On 30 Aug, 09:39, [EMAIL PROTECTED] (Amichai Teumim) wrote:
  Hi
 
  I'm trying to understand subroutines.
 
  #!/usr/bin/perl
 
  marine()
 
  sub marine {
$n += 1; #Global variable $n
print Hello, sailor number $n!\n;
 
  }
 
  This doesn't work. Is marine() incorrect? How would I call the sub marine?
 
  Thanks
 
  Amichai
 
 You can't use somting BEFORE you have created it try to call and
 call sub with name and () and ;

Can't you! I always have my subroutines at the bottom of the file and 
the main part at the top. It works for me.

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




Re: marine subroutine

2007-08-30 Thread Beginner
On 30 Aug 2007 at 17:29, Martin Barth wrote:

 On Thu, 30 Aug 2007 15:39:14 +0100
 Andrew Curry [EMAIL PROTECTED] wrote:
 
  That's rubbish,
 
 but you get a warning like:
 
 main::a() called too early to check prototype at -e line 1.
 
 Use Prototypes at the beginning of your file if you want to write the subs at 
 the end.


I don't get that either !!!

#!/bin/perl
###  junk.pl ###
use strict;
use warnings;

sayhello();


sub sayhello {

print hello\n;

}


 perl junk.pl
hello





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




Re: Logging STDERR and other output

2007-08-30 Thread Beginner
On 30 Aug 2007 at 10:07, Mumia W. wrote:

 On 08/30/2007 09:37 AM, Beginner wrote:
  [...]
  
  I tried the INIT option and that worked also and I liked the fact 
  that my `perl -c myscript.pl` sent it's output to screen and not my 
  log file and I can use a scalar for logfile. 
  
  q1) Does this still give me the effect of getting any errors from the 
  other modules directed to our $logfile?
  
 
 Probably not. There's no better way than to try it and see if it works. 
 Read perldoc perlmod too.

Not sure how conclusive this is but if I put 

print STDERR Just testing\n;

in one of the used modules it does get logged to the logfile. However 
is appears at the top of the log!! Before all the other messages even 
thought that module's functions are not called to near the end. 

  q2) Will our $logfile now be a shared variable across all my modules?
 Try it and see.

No. It's not.

  q3) The $debug/verbose question: Will I have to pass subroutines in 
  other modules the $debug value if I am going to ask for more output, 
  or if I do the same to $debug as I did with $logfile, use our instead 
  of my. Will that allow those subroutines to check if debug is 
  enabled?

 Most people create a logging module if they want total control over 
 logging. That module might have a packag $debug_level variable that 
 determines how much information is logged.
 
 However, the Perl error and warning messages don't fit your logging 
 model, so you'll probably have to write something yourself or find it on 
 CPAN.

Log::Handler looks pretty comprehensive. 
Thanx for the tips.
Dp.


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




Mirror service closure

2007-08-07 Thread Beginner
The Joint Information Systems Committee (JISC) run for academic 
institutions has closed the mirror service in the UK as of the 31st 
July. 

What a shame.



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




Re: Mirror service closure

2007-08-07 Thread Beginner
On 7 Aug 2007 at 5:44, Jeff Pang wrote:

 The Joint Information Systems Committee (JISC) run for academic
 institutions has closed the mirror service in the UK as of the 31st
 July. 
 
 
 
 What mirror?CPAN or perl.com?

CPAN was one of them but they mirrored lots of O/S material, Fedora, 
slackware...that I know of.

Dp.





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




Re: problem with Sterling pound sign

2007-08-06 Thread Beginner
On 6 Aug 2007 at 12:50, Rob Dixon wrote:

 Dermot Paikkos wrote:
 
  CGI;
  Mime::Lite;
 
  I am trying to take the input from a text field from a html page and
  send it as an email. The text contains a UK sterling £ sign. It looks
  fine on in the html page but when I send the mail or output the text
  to STDERR, it gets transformed into this: £
 
  Here are a few of the lines from the script:
 
  33  my $str = $q-param('pro');
  34  my ($p) = ($str =~ /THIS IS GOING TO COST (.*)320/);
  35  my $o = ord($p);
  36  my ($hex) = unpack( 'H', $p);
  37  print STDERR Text=,$q-param('pro'), \$p\ $hex $o\n;
 
  And this is the output:
  Text=THIS IS GOING TO COST £320 £ c 194
 
  I am a bit lost by this as I thought CGI did the heavy lifting with
  character-encoding. Can anyone give me some pointers?

 Hey Dermot

 I think you are grabbing two characters from the text instead of one.
 Your ord() is looking only at the first byte (and your unpack only at the
 first four bits!) and HTML entity #194; is capital A circumflex. Quite
 what it's doing in there I don't know, but try using just /(.)320/ as your
 regex (it's not optional and you don't want more than one). You should get
 a character code of 163 for the pound sign.

Thanx for the tip Rob and your right that my Regex was too greedy. I
now have this:

30  my $str = $q-param('pro');
31  my $length = length($str);
32  my ($p1,$p2) = ($str =~ /(.)(.)320/);
33  my $o1 = ord($p1);
34  my $o2 = ord($p2);
35  my ($hex1) = unpack( 'H', $p1);
36  my ($hex2) = unpack( 'H', $p2);
37  print STDERR Project=,$q-param('pro'), \$p1\ \$p2\ $hex1
$hex2 $o1 $o2 $length\n;


Which outputs this:
Text=THIS IS GOING TO COST £320  £ c a 194 163 27

Interestingly I count 26 characters in the field proir to submitting
but length is reported as 27 once it in the CGI.

So the character is there but it is some misinterretation of the
space prior to that as #194; If I copy the data from the field into a
text/hex editor it's shown x20 (SPace).

UTF-8: The referring page has this in the head:
meta http-equiv=Content-Type content=text/html;charset=utf-8 
which I think should make it legitimate utf-8. I have tried using
charset = 'utf-8' in the start_html prior to readbut wait there
is charset and $q-charset('utf-8') gives me the desired result.

So thanx W.Mumia.
Dp.




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




Re: Perl directory listing program

2007-06-12 Thread Beginner
On 12 Jun 2007 at 16:26, [EMAIL PROTECTED] wrote:

 Looking for some help here you perl geniuses you : )
 
 I need a program that will list all of the files in a directory.
 Without any arguments the program will list only the files (not
 directories) in the current directory.  But I must have some command
 line options:
 
 -d with 0 or 1 directory argument if no argument is given, the cwd
 is used.  If the argument given is not a directory an error is thrown.
 The output needs to have the following headers:
 File Name | Size | Owner | Group ( with no pipes)
 
 -l displays a long listing (can be used with -d as script.pl -l -d
 dirname)
 The output needs to have the following headers:
 File Name | Size | Owner | Group (with no pipes)
 
 no parameters - show the files in the cwd
 The output needs to have the following header:
 File Name


You certainly know exactly what you want.

perldoc -f readdir  # how to read a dir and grep for files only

perldoc perlvar # for an explanation of @ARGV and processing of 
command-line args.

perldoc -f sprintf/printf   # For a way to nicely format some 
headers 
or
perldoc -f format   # For an alternative way to format some 
headers.

See how you get on then, if your stuck, mail the list showing what 
you've tried and your'll get more pointers then.

Good luck,




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




Re: Using SOAP::Lite

2007-06-11 Thread Beginner
Going to top post because I am not referring to your code Mike as I 
am not experienced enough to help directly.

Have you tried the +trace switch?

use SOAP::Lite +trace;

Also there is the yahoo group to try. Sorry if I am stating the 
obvious.

Thanx,
Dp.


On 8 Jun 2007 at 12:02, Mike Blezien wrote:

 Hello,
 
 I appologize for the long posting, but  was hoping to get some feedback as to 
 what we are doing wrong. We are trying to integrate with a XML Gateway that 
 uses 
 SOAP. This our first time at trying to use SOAP w/Perl and not having alot of 
 luck. Below is the code snip and Request/Response structures used by the 
 gateway. If you have experience with using SOAP and Perl, I'd really 
 appreciate 
 your assistance. If there is a better way to do this, please contact me 
 directly 
 off the list and be happy to discuss hiring you to put this together 
 correctly.
 
 #
 # CODE SNIP
 my $soap = SOAP::Lite
 - uri('https://www.edentifyservices.com/')
 - proxy('https://www.edentifyservices.com/XMLGateway/Request.asmx')
 - on_action( sub { return 'http://tempuri.org/ProcessRequest' });
 
 # Format the SOAP envelope
 my $method = SOAP::Data-name('ProcessRequest')-attr({xmlns 
 ='http://tempuri.org/'});
 
 # Format the SOAP body
 my $query = SOAP::Data-name(ProcessRequest = SOAP::Data-value(
  SOAP::Data-name(ServiceName='idalert'),
  SOAP::Data-name(XMLRequest='XMLRequestLine'), # THIS LINE PRODUCES SOAP 
 ERROR
  SOAP::Data-name(Userid='USERID'}),
  SOAP::Data-name(password='PWD'),
  SOAP::Data-name(Options='OPTIONS'))
  );
 
 # Query the web service
 my $result = $soap-call($method = $query);
 
 print $cgi-header();
 
 if($result-fault)
  {
 print Edentify Web Service Failed!\n;
 print join ', 
 ',$result-faultcode,$result-faultstring,$result-faultdetail;
  }
 else
  {
   # Print out the results one by one
   print ResponseType =  . 
 $result-valueof('//ProcessRequestResponse/ProcessRequestResult/EdentifyResponse/responsetype')
  
 . br;
   print Code =  . 
 $result-valueof('//ProcessRequestResponse/ProcessRequestResult/EdentifyResponse/code')
  
 . br;
   print Message =  . 
 $result-valueof('//ProcessRequestResponse/ProcessRequestResult/EdentifyResponse/message')
  
 . br;
   print TransID =  . 
 $result-valueof('//ProcessRequestResponse/ProcessRequestResult/EdentifyResponse/transactionid')
  
 . br;
   # NO RESULTS RETURNED.
  }
 # END CODE SNIP
 
 #
 # XMLRequest format for above XMLRequest:
 XMLRequestLine=idalertusernameUSERNAME/usernamecandidates
 candidatefirstnameFNAME/firstnamemiMNAME/milastnameLNAME/lastname
 suffixSUFFIX/suffix
 locatorID/locatorssnSSN/ssndobBDAY/dob
 addressaddress1ADDR1/address1address2ADDR2/address2cityCITY/city
 stateSTATE/statezipZIP/zip/address/candidate/candidates/idalert
 
 
 # SOAP REQUEST/RESPONSE STRUCTURES
 
 # REQUEST
 POST /XMLGateway/Request.asmx HTTP/1.1
 Host: www.edentifyservices.com
 Content-Type: text/xml; charset=utf-8
 Content-Length: length
 SOAPAction: http://tempuri.org/ProcessRequest;
 
 ?xml version=1.0 encoding=utf-8?
 soap:Envelope xmlns:xsi=http://www.w3.org/2001/XMLSchema-instance;
 xmlns:xsd=http://www.w3.org/2001/XMLSchema; 
 xmlns:soap=http://schemas.xmlsoap.org/soap/envelope/;
   soap:Body
 ProcessRequest xmlns=http://tempuri.org/;
   ServiceNamestring/ServiceName
   XMLRequeststring/XMLRequest
   Useridstring/Userid
   passwordstring/password
   Optionsstring/Options
 /ProcessRequest
   /soap:Body
 /soap:Envelope
 ###
 RESPONSE
 HTTP/1.1 200 OK
 Content-Type: text/xml; charset=utf-8
 Content-Length: length
 
 ?xml version=1.0 encoding=utf-8?
 soap:Envelope xmlns:xsi=http://www.w3.org/2001/XMLSchema-instance;
 xmlns:xsd=http://www.w3.org/2001/XMLSchema; 
 xmlns:soap=http://schemas.xmlsoap.org/soap/envelope/;
   soap:Body
 ProcessRequestResponse xmlns=http://tempuri.org/;
   ProcessRequestResultstring/ProcessRequestResult
 /ProcessRequestResponse
   /soap:Body
 /soap:Envelope
 #
 
 
 Mike(mickalo)Blezien
 ===
 Thunder Rain Internet Publishing
 === 
 
 -- 
 To unsubscribe, e-mail: [EMAIL PROTECTED]
 For additional commands, e-mail: [EMAIL PROTECTED]
 http://learn.perl.org/
 
 



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




Algorithm or module needed

2007-06-01 Thread Beginner
Hi,

I am trying to copy some file from a removable HDD to a network 
drive. I want replicate the directory structure and omit un-needed 
files.

The directory paths a 4-5 levels deep and I am trying to work out an 
efficient way to recreate the directory path.

What I've been doing is using File::Find to collect the file and then 
in the coderef calling the following subroutine to check the path but 
i didn't go too far as my method seemswell not well formed.

The path to a source file looks like:

e:/Dir1/Day 1/AM/01/myfile.jpg


use strict;
use warnings;
...
...snip

sub check_dir {

# @_ = File::Find::dir

 my $path = shift;
 return unless (-e $path);

# Split the path on it's parts.
 my @parts = split('/',$path);

# Loop from 1 to skip the first part of the path.
 for (my $i = 1; $i = $#parts; ++$i)  {

my $l = $dist.'/'.$parts[$i];
if (! -e $l) {
print Checking $l\n;
my $j = $i + 1; # urg!
my $lev = $dist.'/'.$parts[$i].'/'.$parts[$j];
if (! -e $lev) {
print Checking $lev\n;
}
}
 }

Can anyone offer me some advice with this?
Thanx,
Dp.


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




Re: Algorithm or module needed

2007-06-01 Thread Beginner
Thanx that's done exactly what I wanted.
Dp.

On 1 Jun 2007 at 16:34, Xavier Noria wrote:

 On Jun 1, 2007, at 4:29 PM, Beginner wrote:
 
  Hi,
 
  I am trying to copy some file from a removable HDD to a network
  drive. I want replicate the directory structure and omit un-needed
  files.
 
  The directory paths a 4-5 levels deep and I am trying to work out an
  efficient way to recreate the directory path.
 
  What I've been doing is using File::Find to collect the file and
  then in the coderef calling the following subroutine to check the
  path but i didn't go too far as my method seemswell not well
  formed.
 
  The path to a source file looks like:
 
  e:/Dir1/Day 1/AM/01/myfile.jpg
 
 I think you want File::Path's mkpath. File::Path is a standard module.
 
 -- fxn
 
 
 
 
 -- 
 To unsubscribe, e-mail: [EMAIL PROTECTED]
 For additional commands, e-mail: [EMAIL PROTECTED]
 http://learn.perl.org/
 
 



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




module namespace

2007-05-04 Thread Beginner
Hi,

I am using 2 modules under the GGI tree. If I remove CGI and use 
CGI::ProgressBar, am I importing all the methods from the CGI module 
still? 

My experiments suggest not but I thought I read that @INC will search 
up the tree.

If I do this

#use CGI qw/:standard/;
use CGI::ProgressBar qw/:standard/;

my $q = new CGI::ProgressBar;
print $q-header();
...snip

the output looks odd.

Whats more I am having to use the fqn to some of the subroutine in 
CGI::ProgressBar or I get a Undefined subroutine error, ala

CGI::ProgressBar::hide_progress_bar

Am I missing something?

 script below =
use strict;
use warnings;
use Apache2::Const qw(OK DECLINED NOT_FOUND);
use Apache2::RequestUtil ();
use Apache2::RequestRec ();
use HTTP::Request;
use MIME::Lite;
#use CGI qw/:standard/;
use CGI::ProgressBar qw/:standard/;

$| = 1;

sub handler {

 my $q = new CGI::ProgressBar;
 print $q-header();
 print $q-start_html(-title = Sending Email...,
  -style = '/css/psex.css',);

# Define progress bar.
  progress_bar(
 -from =1,
 -to =12,
 -width = 100,
 -colors = [0,'green','red'],
);

# Create the email object
 my $msg = MIME::Lite-new(
From= $q-param(eml),
To  = $q-param(eml),
Subject = Test-Email,
Type= 'multipart/mixed'
);
 for (1..4) {
print $q-update_progress_bar;
 }
# print CGI::ProgressBar::hide_progress_bar;

# Send email
# $msg-send;


 print end_html;


 return OK;
}

1;



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




CGI OO style

2007-05-04 Thread Beginner
Hi Again,

I am trying to make a progressbar and am stuck. I might not sure if 
it my lack of understanding of the differences between the OO style 
or function-oriented style (to paraphrase the Stein-monster) of 
writing CGI scripts.

Script 1 uses the function style and works albeit with one javascript 
error.

Script 2 is my effort at the OO style. It fills my http logs with 
errors as well as causing a similar number of javascript errors.

The only think that looks relevant in the module documents is under 
bugs, caveats, todo:

Parameter passing doesn't match CGI.pm

I not sure what that means exactly. Is it relevant?

So is my style wrong or am I changing the expected behaviour of the 
module if I use an OO style or is it something else altogether.

Thanx (sorry for the long-winded post),
Dp.

 script 1 ===
#!/usr/bin/perl

use strict;
use warnings;
use CGI::ProgressBar qw/:standard/;

$| = 1;

 my $q = new CGI::ProgressBar;
 print header,
start_html(-title = Testing,
   -style = {-src = '/css/mycss.css'},
),
p('A test'),

# Define progress bar.
  progress_bar(
 -from = 1,
 -to = 50,
 -debug = 1,
 -width = 30,
);

 for (1..5) {
print update_progress_bar;
sleep 1;
 }
 print hide_progress_bar;
 print end_html;
 enf of script 1 

== script 2 
#!/usr/bin/perl

use strict;
use warnings;
use CGI::ProgressBar qw/:standard/;


$| = 1;

 my $q = new CGI::ProgressBar;
 print $q-header;
 print $q-start_html(-title = A test,
  -style = {-src = '/css/mycss.css'},
);
 $q-p('Sending Mail');

# Define progress bar.
  $q-progress_bar(
 -from = 1,
 -to = 12,
 -debug = 0,
 -width = 30,
);

 for (1..5) {
print $q-update_progress_bar;
sleep 1;
 }
 print $q-hide_progress_bar;

 print $q-end_html;

=== end of script 2 


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




Re: Regexp

2007-04-25 Thread Beginner
On 25 Apr 2007 at 18:58, Somu wrote:

 why wont the following work?
 
  $q = shift;
  $p = pass;
  if ( $q =~ m/$p/i ) { print 'match' }
 
  But it works on changing the $q and $p places..

Not sure but it works for me.


#!/bin/perl

use strict;
use warnings;

my $q = shift;
my $p = pass;
 if ( $q =~ m/$p/i ) { print 'match' }

perl junk.pl pass
match
perl junk.pl past




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




A little bit of SOAP

2007-04-20 Thread Beginner
Hi,

I am trying my hand a SOAP::Lite and wanted some enlightenment.

I have created a test file (soaptest.pl) which acts as a server. 
soaptest has a subroutine called ReNameTiff which needs 2 arguments, 
a path to the original file and a new name for the file. Because 
SOAP::Lite is OO strange things seem to happen to the arguments that 
get passed to the subroutines I've made.

This is a snip of the client:

my $soap = SOAP::Lite
- uri('http://myserver/Images')
- proxy('http://myserver/soap/soaptest.pl')
- ReNameTiff($path,$splnum); 

my $res = $soap-result;
print STDERR Result was $res\n;

In this example the args are quoted together and to access them I 
have to do split them like this:

my $self = shift;
my $args = shift;
my ($path,$newname) = split(/,/,$args);
print STDERR Self=$self, Path=$path, NewName=$newname, 
[EMAIL PROTECTED] ARGS=$args\n;


This seems a bit loose and prone to error, what if the path had a 
comma in?

What is the correct way to pass arguments in OO? Is there a practise 
I am missing. The reading and examples I have seen still use shift so 
I think I am sending the args incorrectly but if I don't quote them 
only the first argument comes through.

Thanx,
Dp.


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




Re: Problems installing XML modules

2007-04-19 Thread Beginner
Hi,

On 19 Apr 2007 at 12:21, Kaptein, A.M. wrote:

 
 Hello, 
 
 I just started using Perl,and I want to install some module to handle XML 
 files. Below is the error message I get. 
 Could someone  help me ? Please tell me if you need some more information 
 about the problem. 
 
 Thanks, 
 
 Rianne

 Looks good
 Writing Makefile for XML::NamespaceSupport
 Can't exec usr/bin/make: No such file or directory at 
 /usr/lib/perl5/5.8.8/CPAN.pm line 4565.
   usr/bin/make  -- NOT OK
 Running make test
   Can't test without successful make
 Running make install
   make had returned bad status, install seems impossible
 Running make for G/GR/GRANTM/XML-SAX-0.15.tar.gz
   Is already unwrapped into directory /home/akaptei1/.cpan/build/XML-SAX-0.15
 
   CPAN.pm: Going to build G/GR/GRANTM/XML-SAX-0.15.tar.gz
 
 Can't exec usr/bin/make: No such file or directory at 
 /usr/lib/perl5/5.8.8/CPAN.pm line 4565.
   usr/bin/make  -- NOT OK
 Running make test
   Can't test without successful make
 Running make install
   make had returned bad status, install seems impossible
 

I'm no expert but it read's like you haven't got a version of gnu 
make installed. Is there a /usr/bin/make? The path to make looks a 
bit wrong, presumably there shold be a leading slash / at the 
beginning of the path;  /usr/bin/make as opposed to usr/bin/make.

Just a guess. Hopefully someone else will have more useful info for 
you,

Good luck,
Dp.


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




Re: Uninstalling perl module

2007-04-13 Thread Beginner
On 13 Apr 2007 at 6:28, [EMAIL PROTECTED] wrote:

 Hi,
 
 I am using cpan to install modules.
 From time to time I have to uninstall a module. 
 Untill now I did not find a tool to do it. 
 Is there an official tool for this?
 


Try this. It's not a tool but it is the Offical way to remove a 
module.

http://www.cpan.org/misc/cpan-faq.html#How_delete_Perl_modules

Thanx,
Dp.


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




Can I map this

2007-04-04 Thread Beginner
Hi All,

I have a list of names all in uppercase that I would like to 
capitaIise. I can't help but think that map could make short work of 
this loop but I am not sure how. Is it possible to use map here 
instead of a for loop? I can see there are going to be issues with 
double-barrelled names but I'll cross that bridge later.


Thanx,
Dp,.

while (DATA) {

 my @words = split(/\s+/,$_);
 my $str;
 foreach my $w (@words) {
my $s = lc($w);
$s = ucfirst($s);
$str .= $s.' ';
 }
 print STR=$str\n;
}

__DATA__ 
SOME NAME
SOMEONE WITH FOUR NAMES
ONE WITH THREE
A-HYPENED NAME


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




Trying to make things portable

2007-04-02 Thread Beginner
Hi,

I am trying to group some common subroutines into a module. As I use 
both Win32 and *nix systems I wanted the the routines that use the 
file system to be able to work in both environments and handle paths 
like /var/path/to/dir and h:\home\dir equally well.

I know that perl will treat h:/home the same as h:\home but I imagine 
that there is more to making a module portable than simply s!\/!\\! 
all paths.

Is there a trick to this? Should you use OS detection and then start 
converting the path or is there a module that will do the work for 
you?

Thanx,
Dp.


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




XML parsing REST responses

2007-03-29 Thread Beginner
Hi,

I might be in above my head here so bear with me if I am not making 
sense.

I have to retrieve and extract an xml fragment from a REST server. I 
have followed some examples from the Web Services book. I am able 
to retrieve the data via LWP::UserAgent but I am baffled by the hash 
ref that's returned. Data::Dumper prints it as this (excuse the 
formatting) :

$VAR1 = bless( {
 '_protocol' = 'HTTP/1.1',
 '_content' = 'address id=1029
  addressLine1YORK/addressLine1
  addressLine2W1T 6RF/addressLine2
  addressLine3/addressLine3
  addressLine4/addressLine4
  addressLine5/addressLine5
  country id=227/
  postcodeW1T 6RF/postcode
/address',
 '_rc' = 200,
 '_headers' = bless( {
'client-date' = 'Thu, 29 Mar 
2007 11:20:51 GMT',
'content-type' = 'text/xml',
'client-response-num' = 1,
'client-peer' = 
'127.0.0.1:8182',
'content-length' = '256',
'server' = 'Restlet-
Engine/1.0b14'
  }, 'HTTP::Headers' ),
 '_msg' = 'The request has succeeded',
 '_request' = bless( {
'_content' = '',
'_uri' = bless( do{\(my $o = 
'http://localhost:8182/core/address/1029')}, 'URI::http' ),
'_headers' = bless( {
   'user-
agent' = 'libwww-perl/5.803'
 }, 
'HTTP::Headers' ),
'_method' = 'GET'
  }, 'HTTP::Request' )
   }, 'HTTP::Response' );


I am not sure who I am work with the data. The bless reference means 
I have just stepped into the murky workd of OO perl. The data I am 
after is the address xml fragment at the top.

Can anyone offer me any tips to get me started? How do I reference 
the 'Object' at the top of the response? Is there a module that will 
help 'deserialize' the response?

Thanx,
Dp.




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




Re: To Reference or not to reference

2007-03-29 Thread Beginner
Hi

On 29 Mar 2007 at 12:51, Dukelow, Don wrote:

 I've written a Perl program that declares a hash at the top of the
 program %myHask;.  It has worked great until now when one sub program
 seams to be making its own copy of the hash.  I can find no typo's or
 anything but there my still be one there.  My question is would it be
 better to pass the global hash by reference to each sub program to cut
 down on possible typo errors or just leave it global and fix the problem
 I have?
 

I think pass by reference would be the better way to go. It will 
conserve memory as your not passing all the data around and it will 
ultimately make maintenance easier.

Good luck,
Dp.




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




Re: XML parsing REST responses - RESOLVED

2007-03-29 Thread Beginner
On 29 Mar 2007 at 12:39, Beginner wrote:

 Hi,
 
 I might be in above my head here so bear with me if I am not making 
 sense.
 
 I have to retrieve and extract an xml fragment from a REST server. I 
 have followed some examples from the Web Services book. I am able 
 to retrieve the data via LWP::UserAgent but I am baffled by the hash 
 ref that's returned. Data::Dumper prints it as this (excuse the 
 formatting) :
 
 $VAR1 = bless( {
  '_protocol' = 'HTTP/1.1',
  '_content' = 'address id=1029
   addressLine1YORK/addressLine1
   addressLine2W1T 6RF/addressLine2
   addressLine3/addressLine3
   addressLine4/addressLine4
   addressLine5/addressLine5
   country id=227/
   postcodeW1T 6RF/postcode
 /address',
  '_rc' = 200,
  '_headers' = bless( {
 'client-date' = 'Thu, 29 Mar 
 2007 11:20:51 GMT',
 'content-type' = 'text/xml',
 'client-response-num' = 1,
 'client-peer' = 
 '127.0.0.1:8182',
 'content-length' = '256',
 'server' = 'Restlet-
 Engine/1.0b14'
   }, 'HTTP::Headers' ),
  '_msg' = 'The request has succeeded',
  '_request' = bless( {
 '_content' = '',
 '_uri' = bless( do{\(my $o = 
 'http://localhost:8182/core/address/1029')}, 'URI::http' ),
 '_headers' = bless( {
'user-
 agent' = 'libwww-perl/5.803'
  }, 
 'HTTP::Headers' ),
 '_method' = 'GET'
   }, 'HTTP::Request' )
}, 'HTTP::Response' );
 
 
 I am not sure who I am work with the data. The bless reference means 
 I have just stepped into the murky workd of OO perl. The data I am 
 after is the address xml fragment at the top.
 
 Can anyone offer me any tips to get me started? How do I reference 
 the 'Object' at the top of the response? Is there a module that will 
 help 'deserialize' the response?


My mistake. The examples in the books show how to do that. Basically 
pass SOAP::Deserializer the content returned by LWP and it will do 
all the heavy lifting for you...phew.

so 

my $fragment = parse($res-content);
print $fragment-{'some_tag_value'}, \n;

sub parse {
 use SOAP::Lite;
 return SOAP::Custom::XML::Deserializer-deserialize(shift)-root;
}



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




Regex problem with accented characters

2007-03-27 Thread Beginner
Hi,

I am trying to extract the iso code and country name from a 3 column
table (taken from en.wikipedia.org) and have noticed a problem with
accented characters such as Ô.

Below is my script and a sample of the data I am using. When I run
the script the code beginning CI for Côte d'Ivoire returns the string

CI\tC where as I had hoped for CI\tCôte d'Ivoire

Does anyone know why \w+ does include Côte d'Ivoire and how I can get
around it in future?

TIA,
Dp.


 extract.pl 
#!/usr/bin/perl

use strict;
use warnings;

my $file = 'iso-alpha2.txt';

open(FH,$file) or die Can't open $file: $!\n;
while (FH) {
chomp;
next if ($_ !~ /^\w{2}\s+/);
my ($code,$name) = ($_ =~
/^(\w{2})\s+(\w+\s\w+\s\w+s\w+|\w+\s\w+\s\w+|\w+\s\w+|\w+)/);
print $code\t$name\n;
}
===

 sample data 
...snip
BY  Belarus Previously named Byelorussian S.S.R.
BZ  Belize
CA  Canada
CC  Cocos (Keeling) Islands
CD  Congo, the Democratic Republic of the   Previously named Zaire
ZR
CF  Central African Republic
CG  Congo
CH  Switzerland Code taken from Confoederatio Helvetica, its
official Latin name
CI  Côte d'Ivoire
CK  Cook Islands
CL  Chile
CM  Cameroon
===

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




Re: How do I generate a hash from an xml document?

2007-03-26 Thread Beginner
On 26 Mar 2007 at 11:55, Dave Adams wrote:

 What are the general steps to building a hash from and xml document?
 
 Here are my steps:
 
 1. Read in xml document using XML::Simple
 2. Create and empty hash
 3. Loop through $VAR1 (the anonymous datastructure) and populate hash
 
 Is this the general idea or is there a simplier way?
 
 Thanks to all,
 DA
 

XML::Simple will return a hash reference from a file handle. $VAR1 is 
the root of the XML document which comes from Data::Dumper.

use strict;
use warnings;
use XML::Simple;
use Data::Dumper;

my $file = 'myfile.xml';
my $config = XMLin($file); # $config is a reference to a hash;
print Dumper($config);  # Print the hash reference.

or

print $config-{'somevalue'},\n;  # To see a single value 
# from 
the doc.


HTH,
Dp.



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




Re: escape character

2007-03-22 Thread Beginner
On 21 Mar 2007 at 20:05, Dr.Ruud wrote:

 Beginner schreef:

  The Iconv route hasn't been too successful either. I tried
  Text::Iconv-new('ISO8859-1','utf8');


  Thinking that my data is currently ISO8859-1but the results were not
  as I had hoped. Where I had MICROSCÓPIO, I got MICROSCÃPIO.

 I don't think you are showing all characters in the utf8-result.

 Also you send your email in ISO-8859-1 encoding (or gmail recoded it for
 you) so we can't check whether your utf8-result is good or bad. I think
 it was good but got lost some characters when you copy-pasted it.


It is difficult to verify what is happening.

My locale is set to
LANG=en_US.UTF-8
LC_CTYPE=en_US.UTF-8

I tried the following:
iconv -f ISO8859-1 -t UTF-8 testfile.xml  testfile-utf8.xml
diff testfile.xml testfile-utf8.xml

...snip
   keywordMICROSCÓPIO/keyword
341c341
   keywordMICROSCÃPIO/keyword

Then
iconv -f UTF-8 -t ISO8859-1 testfile-utf8.xml  andback.xml
diff andback.xml testfile
 [nothing]

I think I am going off topic a bit but I think this means that if the
file comes as ISO8859-1, I can set the xml encoding=ISO8859-1 and
the recipent can use iconv to convert the data back to UTF-8 when
they receive it.

Fingers crossed. Thanx for all the feedback.
Dp.


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




RE: Some basic perl queries

2007-03-22 Thread Beginner
On 22 Mar 2007 at 8:59, Kumar, Akshay wrote:

 Thanks for the people who responded to original query.
 Another related query.
 Whats the best way to specify common set of include library directories,
 so that I don't end up including (use lib OR -I) in each file using my
 local modules. (recursive include!)
 

That was what this line did

quote from Jeff:

use lib qw(/path/1 /path/2);

Here given the MyLib1 is located in /path/1 and MyLib2 is located in
/path/2.This can work well.



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




Re: tiff images

2007-03-21 Thread Beginner
On 20 Mar 2007 at 19:46, Chris Parker wrote:

 -BEGIN PGP SIGNED MESSAGE-
 Hash: SHA1
 
 Rob Dixon wrote:
  Chris Parker wrote:
 
  Hello all,
 
  How do I get text out of a tiff image?  Scenario is that I have alot of
  directories named (ex. 000, 020, 000) with files inside along the same
  line ( 000.tiff, 034.tiff) and I need to get the date of the
  paper(000.tiff) so I can rename the folder/directory to that date.
 
  I am not having alot of luck searching for this.  A pointer to a module
  to use along with some docs would be greatly appreciated.
  
  Hi Chris
  
  Image::Info should do what you want. Take a look at:
  
   http://search.cpan.org/~tels/Image-Info-1.24/lib/Image/Info.pm
  
  HTH,
  
  Rob
  
 
 This looks promising.  Now I see the part on
 $image_info($file{Comment}).  How do I get a date out of this?  It is a
 scanned text document in tiff format.
 
 Scenario of what I am trying to do:
 
 c:\bla\image_viewer\107001\8\tiff image.
 I am trying to go from the image_viewer part and recurse down the dir
 tree to each subdir and inside the sub is the tiff.  

I need to pull the
 date out of the tiff image (not the creation date or mod time) and
 append it to the directory name.  I don't have to code with me now, I
 will post what i have tomorrow.

Do you mean that these TIFF files are scans of documents with a date 
on and it's this date your after? If so, I think your looking for an 
OCR solution.

There are many TIFF tags, including the XMP, EXIF, IPTC and PhotoShop 
Reasource (IRB) blocks and they will all store the 
creation/modification date. Unless you have stored the date in one of 
these tags (or created your own) I am not sure you will be able to 
get to it easily.


Have a look below for a complete list of the tags. 
http://www.awaresystems.be/imaging/tiff/tifftags/baseline.html  


Other modlues that might help get metadata out of an image are 
Exif::Tool and Image::Magick.

Good luck,
Dp.


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




Re: How to add a dir to @INC

2007-03-21 Thread Beginner
On 21 Mar 2007 at 17:05, kilaru rajeev wrote:

 Hi,
 
 Can anybody help me to add a directory to @INC variable?
 
 Thanks,
 Rajeev Kilaru
 

Either of these should work. Put them at the top, before you use 
something from somedir.

1) 
use lib '/path/to/somedir';

2) unshift @INC, '/path/to/somedir';

HTH,
Dp.


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




Re: escape character

2007-03-21 Thread Beginner
On 20 Mar 2007 at 12:55, Chas Owens wrote:

 On 3/20/07, Beginner [EMAIL PROTECTED] wrote:
  Hi,
 
  I have a large, 1.3GB xml file that I was trying to validate. It
  turns out that the file has a lot of exotic characters in it such as:
  é
  è
  Ä
  È
  ...etc

  Being a lazy kidda guy, I though I would cat the file and let perl
  make the substitiuations where it found any of these characters. My
  problem is I am not sure how to regex for these characters except to
  look for the hex value. Neither do I know of a way to escape/encode
  them correctly.
 
  I have seen the pragma utf8 but I am not sure my problem is what this
  pragma was designed for. Does anyone have any suggestions for a
  module or method that might take some of the pain out of detecting
  and escaping such characters?


 Be a truly lazy guy and use iconv.


The hex idea might work. If I can locate all the characters in a
file/string that use a hex in a range and the substitute them.
Perhaps something like this would do it (feel free to correct me if I
am wrong)

s/\xc9/'#'.$1.';'/ # Hoping for #201; from É

However it doesn't feel like it's the best approach.

The Iconv route hasn't been too successful either. I tried
Text::Iconv-new('ISO8859-1','utf8');

Thinking that my data is currently ISO8859-1but the results were not
as I had hoped. Where I had MICROSCÓPIO, I got MICROSCÃPIO.

If I can't convert, perhaps I need to XHTML escape them so
MICROSCÓPIO would become MICROSCOtilde;PIO

Is there are module that can parse and substitute in this way or do I
need to roll my own?

TIA,
Dp.



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




Re: How to add a dir to @INC

2007-03-21 Thread Beginner
On 21 Mar 2007 at 0:00, Jeff Pang wrote:

 
 
 1) 
 use lib '/path/to/somedir';
 
 2) unshift @INC, '/path/to/somedir';
 
 
 This can't work when you add a path to @INC on runtime.
 
 BEGIN {
 unshift @INC,'/path/...';
 }

Do you mean you have to put it in a BEGIN block to work?
Thanx,
Dp.


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




escape character

2007-03-20 Thread Beginner
Hi,

I have a large, 1.3GB xml file that I was trying to validate. It
turns out that the file has a lot of exotic characters in it such as:
é
è
Ä
È
...etc

The area of encoding and internationalisation is one I have no
experience of at all and from what I've heard it is rather complex
and difficult.

Being a lazy kidda guy, I though I would cat the file and let perl
make the substitiuations where it found any of these characters. My
problem is I am not sure how to regex for these characters except to
look for the hex value. Neither do I know of a way to escape/encode
them correctly.

I have seen the pragma utf8 but I am not sure my problem is what this
pragma was designed for. Does anyone have any suggestions for a
module or method that might take some of the pain out of detecting
and escaping such characters?

TIA,
Dp.


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




Sys::Gamin install error

2007-03-15 Thread Beginner
Hi,

OS: FC4
With gamin-0.1.1-3.FC4 and gamin-devel-0.1.1-3.FC4 installed

I have hit an error while trying to install Sys::Gamin. I can can run 
make but the `make test` is failing.

The test file for Sys::Gamin reads:

use Test;
use SGI::FAM;

plan tests = 1;

ok (SGI::FAM::FAMChanged != SGI::FAM::FAMDeleted);


So I tried to install SGI::FAM but when the tests are run, it fails 
again.

The error from SGI::Fam is 
...snip
usr/lib/perl5/vendor_perl/5.8.3 /usr/lib/perl5/vendor_perl 
/usr/lib/perl5/5.8.6/i386-linux-thread-multi /usr/lib/perl5/5.8.6 .) 
at t/fam.t line 1.
BEGIN failed--compilation aborted at t/fam.t line 1.
t/famdubious
Test returned status 2 (wstat 512, 0x200)
FAILED--1 test script could be run, alas--no output ever seen
make: *** [test_dynamic] Error 2


Below is the error from Gamin
...snip
/lib/perl5/vendor_perl/5.8.3 /usr/lib/perl5/vendor_perl 
/usr/lib/perl5/5.8.6/i386-linux-thread-multi /usr/lib/perl5/5.8.6 .) 
at t/gamin.t line 2.
BEGIN failed--compilation aborted at t/gamin.t line 2.
t/gamindubious
Test returned status 2 (wstat 512, 0x200)
FAILED--1 test script could be run, alas--no output ever seen
make: *** [test_dynamic] Error 2


Does anyone know what I am missing? 
TIA,
Dp.


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




sprintf - Rounding down

2007-03-15 Thread Beginner
Hi,

For some reason my sprintf usage is not returning the numbers I had 
expected and appears to be rounding down. Is there something wrong 
with my formatting below.

=== code snip ==

my ($x,$y) = imgsize($fqn);
my $size = $x*$y*3;
my $ksize = sprintf(%.2f,$size/1024); 
my $mbsize = sprintf(%.2f,$ksize/1024);
my $msize = sprintf(%d,$mbsize);
print $_\t$msize\t$mbsize\n;


Output


X329002100.60
X329002200.60
X32900232   2.32
X32900241   1.19
Z220019828  28.45
Z220023552  52.53
Z345007625  25.49
Z42125  25.71

In nearly all of these, I would expect $msize to be rounded up. What 
appears to be happening is that I am getting the int pat of the 
number. What am I doing wrong?

TIA,
Dp.


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




Re: sprintf - Rounding down

2007-03-15 Thread Beginner
On 15 Mar 2007 at 8:05, Tom Phoenix wrote:

 On 3/15/07, Beginner [EMAIL PROTECTED] wrote:
 
  For some reason my sprintf usage is not returning the numbers I had
  expected and appears to be rounding down. Is there something wrong
  with my formatting below.
 
  my $ksize = sprintf(%.2f,$size/1024);
  my $mbsize = sprintf(%.2f,$ksize/1024);
  my $msize = sprintf(%d,$mbsize);
 
 The %d format is for integers, so it always truncates any fractional
 part. The %f is floating, so it rounds. If you want to round to the
 nearest integer, then, use a format like %.0f or %6.0f.

 Does that solve your problem? 

Right on the money! %0.f gives me:

B53904930.59 1
B53904940.58 1
B53904950.54 1
B53904970.54 1
B53904980.53 1
B57009170.53 1
B57009180.54 1

Which is what I wanted.

The sprintf documentation in the perlfunc manpage is quite extensive.

There no problem with the docs, just my understanding of decimal and 
floating point numbers.

Thanx again Tom,
Dp.


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




Re: Sys::Gamin install error

2007-03-15 Thread Beginner
On 15 Mar 2007 at 8:20, Tom Phoenix wrote:

 On 3/15/07, Beginner [EMAIL PROTECTED] wrote:

  I have hit an error while trying to install Sys::Gamin. I can can run
  make but the `make test` is failing.

  BEGIN failed--compilation aborted at t/gamin.t line 2.
  t/gamindubious
  Test returned status 2 (wstat 512, 0x200)
  FAILED--1 test script could be run, alas--no output ever seen
  make: *** [test_dynamic] Error 2

  Does anyone know what I am missing?

 Yes: the output of the test script. :-)

 Frequently, when the test program fails during a BEGIN with no
 standard output, that's because a 'use' directive or something similar
 was unable to load the requested code. Alas, we don't know why it
 failed, because the test harness wasn't kind enough to tell us.

 But you don't have to use the test harness. The trick is to run the
 test programs manually. You can probably see in the output of 'make
 test' the command line that 'make test' used to invoke the test
 program; by using that or a similar invocation you should be able to
 see the diagnostic message. (That invocation includes command-line
 options to load the module from the build directory, among other
 options.)

 Armed with that diagnostic message, you'll have a fighting chance at
 fixing the problem. Good luck with it!

I am not entirely sure I have followed your instructions. What I have
done is, first edit the t/fam.t and added use diagnostics, then
edited the Makefile/test section and made
TEST_VERBOSE=1

Then run `make test` and saw:

t/famCan't locate Test/Helper.pm in @INC...

Installed Test::Helper (Should that have been installed already?)

make clean;Perl Makefile.PL and got a new error:

Ignore Not a known parameter name warnings.WARNING: PRCS_PROJECT is
not a known parameter.
Checking if your kit is complete...
Looks good
'PRCS_PROJECT' is not a known MakeMaker parameter name.
Note (probably harmless): No library found for -lC
Writing Makefile for SGI::FAM

The make tests now fail with a more exotic error message (should I
post the whole thing?). A snip of which is below:

gcc -c   -D_REENTRANT -D_GNU_SOURCE -DDEBUGGING -fno-strict-aliasing -
pipe -I/usr/local/include -D_LARGEFILE_SOURCE -D_FILE_OFFSET_BITS=64 -
I/usr/include/gdbm -O2 -g -pipe -Wp,-D_FORTIFY_SOURCE=2 -fexceptions -
m32 -march=i386 -mtune=pentium4 -fasynchronous-unwind-tables   -
DVERSION=\1.002\ -DXS_VERSION=\1.002\ -fPIC -
I/usr/lib/perl5/5.8.6/i386-linux-thread-multi/CORE   FAM.c
FAM.xs: In function âfamerrorâ:
FAM.xs:123: warning: return discards qualifiers from pointer target
type
Running Mkbootstrap for SGI::FAM ()
chmod 644 FAM.bs
snip
/usr/bin/perl -MExtUtils::MY -e MY-fixin(shift)
blib/script/monitor
PERL_DL_NONLAZY=1 /usr/bin/perl -MExtUtils::Command::MM -e
test_harness(0, 'blib/lib', 'blib/arch') t/*.t
t/famCan't load '/root/.cpan/build/SGI-FAM-
1.002/blib/arch/auto/SGI/FAM/FAM.so' for module SGI::FAM:
/root/.cpan/build/SGI-FAM-1.002/blib/arch/auto/SGI/FAM/FAM.so:
undefined symbol: FAMDebugLevel at /usr/lib/perl5/5.8.6/i386-linux-
thread-multi/DynaLoader.pm line 230.
 at t/fam.t line 5
Compilation failed in require at t/fam.t line 5.
snip
Uncaught exception from user code:
Can't load '/root/.cpan/build/SGI-FAM-
1.002/blib/arch/auto/SGI/FAM/FAM.so' for module SGI::FAM:
/root/.cpan/build/SGI-FAM-1.002/blib/arch/auto/SGI/FAM/FAM.so:
undefined symbol: FAMDebugLevel at /usr/lib/perl5/5.8.6/i386-linux-
thread-multi/DynaLoader.pm line 230.
 at t/fam.t line 5


Line 5 of t/fam.t reads:

use SGI::FAM qw(FAM_DEBUG_ON FAM_DEBUG_OFF);

I guess I could ask the maintainer/author. Is there anything from
that output that stands out? I can't say that I can see a trail here.
Thanx,
Dp.




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




polling a directory

2007-03-14 Thread Beginner
Hi,

I am trying to find a means of monitoring a directory for activity. I 
would like a perl process to aware if a file has been dropped into a 
specific folder and then take some action.

In the past I have used cron for this but I was thinking this isn't 
the best choice because 1) You have to spawn a very frequently to try 
to achieve real-time action 2) The high frequency spawning of a perl 
script is quite expensive in terms of resources 3) There is the 
potential for one process to collide with another.

One way would be to have a script that did while (1) and a sleep when 
nothing was found but again this seems primitive. Is this something 
that a daemon module might help with? Does anyone have an idea that 
might help? 

TIA,
Dp.


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




Query regarding seek and tell

2007-03-12 Thread Beginner
Hi,

When I ask for the filehandle position (tell) it is reporting the 
pointer as being a few bytes further along than I expect it to be. 
For instance if I do this:

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

my ($start,$d,$var);

my $file = 'myjpeg.jpg';
open(FH,$file) or die Can't open $file: $!\n;
binmode(FH);

while (FH) {

if ($_ =~ /\xFF\xC0/) {  # Start of frame header.
print Found start of frame at $start\n;
seek(FH,$start,0);
my $read = read(FH,$var, 2);
print unpack(H*, $var), \n;
# This should return ff C0 or at least the next 2 bytes
print read $read characters at $start and got $var\n; 
}
}

It tells me that it is reading at 7345. Yet when I open the same file 
in a hex editor and search for 'ff c0' it reports the position as 
7290.

Is this because it is reading the file in line by line? Setting $/; 
doesn't change the output. Can anyone explain this? 

TIA,
Dp.


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




Re: Query regarding seek and tell

2007-03-12 Thread Beginner
On 12 Mar 2007 at 9:34, Tom Phoenix wrote:

 On 3/12/07, Beginner [EMAIL PROTECTED] wrote:
 
  When I ask for the filehandle position (tell) it is reporting the
  pointer as being a few bytes further along than I expect it to be.
 
  binmode(FH);
 
  while (FH) {
 
 If it's a binary file, you shouldn't read it by lines, which is what
 this does. You should probably use the read function instead; that
 will let you specify how many bytes to read at a time. (And is a while
 loop the right construct for the operation you're performing?)

Obviously not. I fthink this is more what I should be using to read 4 
bytes at a time:

while (read FH, $buf, 4) {

  if ($_ =~ /\xFF\xC0/) {  # Start of frame header.
  print Found start of frame at $start\n;
 
 Where did you put a value into $start?

Yes some over zealous editing on my part. I was trying to snip out 
all the irrelevant stuff and removed 
$start = tell FH;

 Finally, it looks as if you're looking into the data of a jpeg/jfif
 file. Isn't there a module that will help you do what you want without
 mucking around in the raw bytes?

I must admit Tom, you are good. I am indeed looking for a the jpeg 
Start Of Frame marker. When I started writing the last post I did do 
a preamble about re-inventing the wheel but that got chopped too.

What I am tring to do is find the x and y dimension of a jpeg which 
can be found in the first few bytes of the header. ImageMagick or 
similar would do this but I am trying to help a friend who has to get 
the dimension so he can work out the uncompressed size of the file 
(x_axis x y_axis x 3 /1024 /1024). He doesn't have access to perl or 
c libraries and will have to read the file in byte by byte to 
determine the size of the file and it's a good lesson in binary 
reading for me too :-)

 Hope this helps!

You haven't failed yet!
 
 --Tom Phoenix
 Stonehenge Perl Training



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




Re: Removing blank lines

2007-03-12 Thread Beginner
On 12 Mar 2007 at 11:09, Grant wrote:

 Hello,
 
 I'm having a lot of trouble figuring out how to remove blank lines
 from my HTML.  The lines are generated by my shopping cart.  I use
 (and highly recommend) interchange:
 
 http://www.icdevgroup.org
 
 I basically want to wrap all of my code in [filter
 no_blank_lines][/filter].  no_blank_lines is defined this way:
 
 CodeDef no_blank_lines Routine EOR
 sub {
 my $val = shift;
 #$val =~ s/\s+//g;
 #$val =~ s/\s*\n+\s*/\n/g;
 #$val =~ s/[^\S\n]*\n\s*\n/\n/g;
 $val =~ s/\n\n+/\n/g;
 return $val;
 }
 EOR

This is untested but usually works for me

$val =~ s/^$//g

not sure you'll need the gobal switch if you'r reading line by line 
but it can't hurt.

 Those are all regexp's I've tried.  They all seem to do nothing except
 the first one removes all whitespace including the spaces in between
 characters in my code which obviously breaks everything.  Can anyone
 suggest a solution?

HTH,
Dp.



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




Re: Query regarding seek and tell

2007-03-12 Thread Beginner
On 12 Mar 2007 at 10:49, Tom Phoenix wrote:

 On 3/12/07, Beginner [EMAIL PROTECTED] wrote:
 
  What I am tring to do is find the x and y dimension of a jpeg
 
 Ah, Image::Size.
 
 http://search.cpan.org/~rjray/Image-Size-3.01/lib/Image/Size.pm
 
 Enjoy!

Image::size  Image::Info and the excellent Image::MetaData::JPEG. Am 
looking at the source now to see if I can gleam the way they do it. 
The grey matter is pulsing already but it's fun, I like this byte 
reading stuff :-)
...
# Extract the segment header.
($marker, $code, $length) = unpack(a a n, $segheader);
...

Thanx

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




Re: centralized variable variables

2007-03-06 Thread Beginner
On 6 Mar 2007 at 6:08, Jeff Pang wrote:

  Is it possible to send an variable (through the env or as an 
 argument, or ) so I can use the variable $dir from the module 
 test.pl to set the variable $vardir in param.pl. ??
 
 
 Yes you can.
 You may declare the vars wanted to be shared in the module as package 
 variable using Perl's our statement.
 
 $ cat test.pl 
 use strict;
 our ($path1,$path2);
 require param.pl;
 print(path1 $path1\n);
 print(path2 $path2\n);
 
 $ cat param.pl 
 #!/usr/bin/perl
 use strict;
 my $basepath = /var/tmp;
 my $vardir = dir;
 our $path1=$basepath/$vardir/path1;
 our $path2=$basepath/$vardir/path2;
 
 1;

Is the 1; required here? I thought it was only needed in packages. Am 
I mistaken?

Thanx,
Dp.


 $ perl test.pl 
 path1 /var/tmp/dir/path1
 path2 /var/tmp/dir/path2
 




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




Centralised variables - different issue

2007-03-06 Thread Beginner
Hi,

Following on from the earlier thread about storing common code in a 
central file, I have hit a problem when trying to do something 
similar.

I have been toying with SOAP. There seems to be a number of ways to 
create SOAP services and I opted for one of the examples at 
guide.soaplite.com.

So my code looks a bit like this at the moment:

== test.pl ==
#!/usr/bin/perl

use strict;
use warnings;
use Mymodule qw($server);
use SOAP::Transport::HTTP;

SOAP::Transport::HTTP::CGI
-dispatch_to('Test')
-handle;

package Test;   # Is this the problem?

sub hi {
return Hello World;
}

sub bye {
return It's all over;
}

sub Mysub {
return Variable \$server=$server;
}

=

Mymodule looks like this:

=== Mymodules.pm ==
package MyModule;

require Exporter;
use strict;
use warnings;
use SOAP::Lite;

our @ISA= qw(Exporter);
our @EXPORT = qw($server $name);
our $VERSION= 1.00;

our $server = 'localhost.somedomain.com';
our $name = 'Smithe';

1;
==

When I run perl -c test.pl I get 
Global symbol $server requires explicit package name at test.pl 
line 25.
test.pl had compilation errors.

and the same apepars in the server logs. There is a scoping issue 
here but I can't see where it comes from.

Does anyone have any ideas?
Thanx,
Dp.




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




SOAP query

2007-03-05 Thread Beginner
Hi,

I am trying to get started with SOAP. I am using mod_perl::Registry, 
the server script is below.

I want to verify that the number of arguments being passed to the 
server is correct. In the snip below I presumed all the arguments 
would be items with @_ but it looks like all the arguments are in 
list within $_[1]. When a client connects to the service, the logs 
show:

2. Test
2. /home/phil/edits/finished/MFM 1020/2501602.tif, 220123


So it looks like the first argument is always the service and the 2nd 
item is a comma separated list of the other arguments.

Does anyone know if this is the correct behaviour?
Thanx,
Dp.



#!/usr/bin/perl

use strict;
use warnings;
use SOAP::Transport::HTTP;
use File::Basename;
use File::Copy;

SOAP::Transport::HTTP::CGI
-dispatch_to('Test')
-handle;

package Test;

sub ReNameTiff{

my ($path,$num);
# Check the number of arguments. Must be 2;
my $no_args = @_;
if ($no_args != 2) {
return Not enough arguments, expected at two;
}
else {
($path,$num) = @_;
}

# Check the file exists

foreach my $arg (@_) {
print STDERR $no_args. $arg\n;
}

if (-e $path) {

}
else {
return Cannot find $path, @_;
}

my $basename = basename($path);
(my $splnum = $num) =~ s/\///;

return basename renamed to $num;
}


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




Re: Off-Topic: Is the Randall Schwartz of Perl Fame?

2007-03-05 Thread Beginner
Mega. About time too.

On 5 Mar 2007 at 11:56, Mathew wrote:

 http://articles.techrepublic.com.com/2100-1009_11-6164113.html?tag=nl.e019
 
 Mathew
 




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




Re: URL too long

2007-02-28 Thread Beginner
I think GET request are restricted to 256 characters, try using POST 
instead.

HTH,
Dp.


On 28 Feb 2007 at 18:57, Tatiana Lloret Iglesias wrote:

 Hi all,
 
 i have to browse a very long URL from my PERL script and it fails:
 
 http://appft1.uspto.gov/netacgi/nph-Parser?Sect1=PTO2Sect2=HITOFFu=%2Fnetahtml%2FPTO%2Fsearch-adv.htmlr=0p=1f=Sl=50Query=%28%22NRF3%22+AND+%22Colorectal+Cancer%22%29+OR+%28%22NRF3%22+AND+%22Colorectal+Carcinoma%22%29+OR+%28%22NRF3%22+AND+%22Colorectal+Tumors%22%29+OR+%28%22NRF3%22+AND+%22Neoplasms%2C+Colorectal%22%29+OR+%28%22NRF3%22+AND+%22colorectal+cancer%22%29+OR+%28nfe2l3+AND+%22Colorectal+Cancer%22%29+OR+%28nfe2l3+AND+%22Colorectal+Carcinoma%22%29+OR+%28nfe2l3+AND+%22Colorectal+Tumors%22%29+OR+%28nfe2l3+AND+%22Neoplasms%2C+Colorectal%22%29+OR+%28nfe2l3+AND+%22colorectal+cancer%22%29+d=PG01
 
 Do you know how to make it works??
 
 Thanks a lot!
 T
 



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




Re: URL too long

2007-02-28 Thread Beginner
That depends on what your using, CGI or LWP.

A CGI example might be

$q-start_form(-method='POST').

Your need to check out the documentation for a full explanation.

HTH,
Dp.



On 28 Feb 2007 at 19:05, Tatiana Lloret Iglesias wrote:

 Yes! that's the problem, GET method doesnt allow very very long url's ...
 how can I use POST from Perl code? do you have any example?
 
 Thanks!
 T
 
 
 On 2/28/07, Beginner [EMAIL PROTECTED] wrote:
 
  I think GET request are restricted to 256 characters, try using POST
  instead.
 
  HTH,
  Dp.
 
 
  On 28 Feb 2007 at 18:57, Tatiana Lloret Iglesias wrote:
 
   Hi all,
  
   i have to browse a very long URL from my PERL script and it fails:
  
  
  http://appft1.uspto.gov/netacgi/nph-Parser?Sect1=PTO2Sect2=HITOFFu=%2Fnetahtml%2FPTO%2Fsearch-adv.htmlr=0p=1f=Sl=50Query=%28%22NRF3%22+AND+%22Colorectal+Cancer%22%29+OR+%28%22NRF3%22+AND+%22Colorectal+Carcinoma%22%29+OR+%28%22NRF3%22+AND+%22Colorectal+Tumors%22%29+OR+%28%22NRF3%22+AND+%22Neoplasms%2C+Colorectal%22%29+OR+%28%22NRF3%22+AND+%22colorectal+cancer%22%29+OR+%28nfe2l3+AND+%22Colorectal+Cancer%22%29+OR+%28nfe2l3+AND+%22Colorectal+Carcinoma%22%29+OR+%28nfe2l3+AND+%22Colorectal+Tumors%22%29+OR+%28nfe2l3+AND+%22Neoplasms%2C+Colorectal%22%29+OR+%28nfe2l3+AND+%22colorectal+cancer%22%29+d=PG01
  
   Do you know how to make it works??
  
   Thanks a lot!
   T
  
 
 
 
  --
  To unsubscribe, e-mail: [EMAIL PROTECTED]
  For additional commands, e-mail: [EMAIL PROTECTED]
  http://learn.perl.org/
 
 
 
 



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




A long shot

2007-02-28 Thread Beginner
Hi All,

This is a long shot.

I have a list of files:

hash.buckets
page.index
page.wordlist
word.list
word.index
hash.file


They are part of a SQL/Apache/mod_perl installation and these are 
some kind of indices for searches. I want to examine the contents if 
possible.

It's quite possible that these files were made by a perl hacker but I 
am unsure. Do they look like something that may have been made by a 
perl module? Is this a job for pack/unpack?

Any thought appreciated.
Thanx,
Dp.


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




Re: A long shot

2007-02-28 Thread Beginner
On 28 Feb 2007 at 9:58, Tom Phoenix wrote:

 On 2/28/07, Beginner [EMAIL PROTECTED] wrote:
 
  I have a list of files:
 
  hash.buckets
  page.index
  page.wordlist
  word.list
  word.index
  hash.file
 
 
  They are part of a SQL/Apache/mod_perl installation and these are
  some kind of indices for searches. I want to examine the contents if
  possible.
 
 Have you tried the unix commands file and od?

strings gives me some odd output, not really usable, file just says 
it's data and od gives me a hex dump, again not much to work with.

  It's quite possible that these files were made by a perl hacker but I
  am unsure. Do they look like something that may have been made by a
  perl module?
 
 I don't recognize these filenames, but maybe someone else does.
 Guessing from the names, though, they look like files that could be
 used as some kind of indices for searches. Which is to say, if
 you're worried about malicious intent, it either doesn't exist or has
 been cleverly concealed. (Are any of them executable? If not, what's
 the worry?)

The issue is that there index is corrupt or rather there is data 
missing from them. Rebuilding them causes the server to crash so I 
wanted to try and extract the data so I could compare it against the 
database to see what was missing and add it.

  Is this a job for pack/unpack?
 
 Could be, especially if you know (or can determine) the file format.
 Do you have any documentation on the program that created these files,
 or one that reads them? If not, I wouldn't waste too much time on
 these files; reverse engineering the index's hash function could take
 weeks, or months. It would be faster to install a new index system
 from scratch.

I think your right. I was hoping that perhaps they were made with 
something like pack or storable which would make the task possible.
 
 Good luck with it!

Thanx for your time.
Dp.



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




Record separator and regex switch

2007-02-26 Thread Beginner
Hi,

I am trying to parse some dhcp-lease files to extract the ip, mac and 
hostname. 

I am struggling to get either, the regex of the $/, correct. I am not 
sure which combination of these I should use.

There is some sample data and my best effort below. Can anyone offer 
any pointers?

TIA,
Dp.


=== Sample Data =
...
lease 196.222.237.209 {
  starts 5 2007/02/23 17:53:57;
  ends 6 2007/02/24 17:53:57;
  binding state active;
  next binding state free;
  hardware ethernet 00:60:04:28:28:01;
  client-hostname lab.mydomain.com;
}
lease 196.222.237.209 {
  starts 5 2007/02/23 17:53:57;
  ends 6 2007/02/24 17:53:57;
  binding state active;
  next binding state free;
  hardware ethernet 00:60:04:38:38:01;
  client-hostname lab.mydomain.com;
}
lease 196.222.237.195 {
  starts 5 2007/02/23 17:54:04;
  ends 6 2007/02/24 17:54:04;
  binding state active;
  next binding state free;
  hardware ethernet 00:0c:c1:33:31:0d;
  uid \001\000\014\361\3231\015;
  client-hostname puck;
}
=

== My effort ===
#!/usr/bin/perl

use strict;
use warnings;

my $file = '/var/lib/dhcp3/dhcpd.leases';
my ($ip,$mac,$host);

#$/ = }\n;
$/ = '';

open(FH,$file) or die Can't open $file: $!\n;

while (FH) {
chomp;
($ip,$mac,$host) = ($_ =~ 
/lease\s+(\d{3}\.\d{3}\.\d{3}\.\d+).*thernet\s+(\d{2}:\d{2}:\d{2}:\d{2
}:\d{2}:\d{2}).*ostname\s+\
(\w+\.scien.*)/smg);

print $ip $mac $host\n;

}
===

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




Re: Record separator and regex switch

2007-02-26 Thread Beginner
On 26 Feb 2007 at 15:58, D. Bolliger wrote:

 Beginner am Montag, 26. Februar 2007 14:50:
  Hi,
 
 Hi
 
  I am trying to parse some dhcp-lease files to extract the ip, mac and
  hostname.
 
  I am struggling to get either, the regex of the $/, correct. I am not
  sure which combination of these I should use.
 
  There is some sample data and my best effort below. Can anyone offer
  any pointers?
 
  TIA,
  Dp.
 
 
  === Sample Data =
 [moved to __DATA__ section below]
  == My effort ===
  #!/usr/bin/perl
 
  use strict;
  use warnings;
 
  my $file = '/var/lib/dhcp3/dhcpd.leases';
  my ($ip,$mac,$host);
 
  #$/ = }\n;
 
 used below :-)
 
  $/ = '';
 
  open(FH,$file) or die Can't open $file: $!\n;
 
  while (FH) {
  chomp;
  ($ip,$mac,$host) = ($_ =~
  /lease\s+(\d{3}\.\d{3}\.\d{3}\.\d+).*thernet\s+(\d{2}:\d{2}:\d{2}:\d{2
  }:\d{2}:\d{2}).*ostname\s+\
  (\w+\.scien.*)/smg);
 
  print $ip $mac $host\n;
 
  }
 
 To keep the demonstration script short, I use a short regex that should be 
 more specific 
 
 #!/usr/bin/perl
 
 use strict;
 use warnings;
 
 {
   local $/=}\n;
   for (DATA) {
 my ($ip,$mac,$host)=
/lease\s+(\S+).*
 ethernet\s+(\S+);.*
 hostname\s+(\S+);
/sx;
 print IP $ip - MAC $mac - HOST $host\n;
   }
 }
 
 __DATA__
 lease 196.222.237.209 {
   starts 5 2007/02/23 17:53:57;
   ends 6 2007/02/24 17:53:57;
   binding state active;
   next binding state free;
   hardware ethernet 00:60:04:28:28:01;
   client-hostname lab.mydomain.com;

...

 Dani
 

Thanx Dani,

That's worked a treat. Just to complete the learning curve, where was 
I going wrong?

Thanx,
Dp.




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




  1   2   >