[30175] in Perl-Users-Digest

home help back first fref pref prev next nref lref last post

Perl-Users Digest, Issue: 1418 Volume: 11

daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Thu Apr 3 16:09:43 2008

Date: Thu, 3 Apr 2008 13:09:09 -0700 (PDT)
From: Perl-Users Digest <Perl-Users-Request@ruby.OCE.ORST.EDU>
To: Perl-Users@ruby.OCE.ORST.EDU (Perl-Users Digest)

Perl-Users Digest           Thu, 3 Apr 2008     Volume: 11 Number: 1418

Today's topics:
    Re: Create two-dimensional Array from string <tzz@lifelogs.com>
    Re: Create two-dimensional Array from string jjcassidy@gmail.com
        Creating a 'load simulator' by calling Perl Programs -  <pgodfrin@gmail.com>
        frustrated in installing modules <ela@yantai.org>
    Re: frustrated in installing modules <smallpond@juno.com>
    Re: frustrated in installing modules <ela@yantai.org>
    Re: frustrated in installing modules <1usa@llenroc.ude.invalid>
    Re: mismatch between Perl 5.6 and Perl 5.8 in printing  <tzz@lifelogs.com>
        New errors of export image format <ela@yantai.org>
    Re: New errors of export image format <glex_no-spam@qwest-spam-no.invalid>
    Re: New errors of export image format <1usa@llenroc.ude.invalid>
        Problem adding new line ! <techrepository@gmail.com>
    Re: Problem adding new line ! <smallpond@juno.com>
    Re: Problem adding new line ! <ben@morrow.me.uk>
    Re: Problem adding new line ! <techrepository@gmail.com>
    Re: Problem adding new line ! <someone@example.com>
    Re: RE Perl Pattern matching <cwilbur@chromatico.net>
    Re: Spelling suggestions for common words - ispell, etc <usenet@davidfilmer.com>
    Re: Spelling suggestions for common words - ispell, etc <joost@zeekat.nl>
        Win32::OLE "Member not found" Adam.L.MacKinnon@gmail.com
        Digest Administrivia (Last modified: 6 Apr 01) (Perl-Users-Digest Admin)

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

Date: Thu, 03 Apr 2008 08:58:07 -0500
From: Ted Zlatanov <tzz@lifelogs.com>
Subject: Re: Create two-dimensional Array from string
Message-Id: <86ej9n6nww.fsf@lifelogs.com>

On Wed, 2 Apr 2008 10:21:23 -0700 (PDT) "pjfalbe@gmail.com" <pjfalbe@gmail.com> wrote: 

pc> I'm looking for the most efficient way to create a two dimensional
pc> array from strings such as

pc> MULTISET{ROW(1     ,'  3667 ','WARREN    ','OH'),ROW(2     ,'  2948
pc> ','SHAKER HTS','OH')}

pc> In this case MULTISET is a collection of rows from a DB.  What I want
pc> todo is efficiently
pc> transform into a 2-dimensional array,  where each row is an array.
pc> And then collect those arrays
pc> into 1 array of arrays.  I'm currently doing this but not very
pc> efficiently.  Any help would be appreciated.

If they are really coming from a DB query, you could use the appropriate
*arrayref DBI functions to get the array back effortlessly.  What you
describe is exactly what they do.  Note there are many DBD::* modules
(the data drivers for DBI) so you may not be limited to classic RDBMS
(Oracle, MySQL, Postgres, etc) queries.  For example see DBD::Google and
DBD::CSV.

Ted


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

Date: Thu, 3 Apr 2008 08:49:11 -0700 (PDT)
From: jjcassidy@gmail.com
Subject: Re: Create two-dimensional Array from string
Message-Id: <3d7e68ac-9446-4921-9008-83bbfbe60a51@a23g2000hsc.googlegroups.com>

On Apr 2, 1:21=A0pm, "pjfa...@gmail.com" <pjfa...@gmail.com> wrote:
> I'm looking for the most efficient way to create a two dimensional
> array from strings such as
>
> MULTISET{ROW(1 =A0 =A0 ,' =A03667 ','WARREN =A0 =A0','OH'),ROW(2 =A0 =A0 ,=
' =A02948
> ','SHAKER HTS','OH')}
>
> In this case MULTISET is a collection of rows from a DB. =A0What I want
> todo is efficiently
> transform into a 2-dimensional array, =A0where each row is an array.
> And then collect those arrays
> into 1 array of arrays. =A0I'm currently doing this but not very
> efficiently. =A0Any help would be appreciated.

Let Perl parse it for you. You can *eval* it.

use Data::Dumper;

sub ROW (@) { return [ @_ ]; }

sub MULTISET (&) { return [ sort { $a->[0] <=3D> $b->[0] } shift()-
>() ];  }

# observe:
my $multi_set =3D eval <<END_EVAL1;
MULTISET{ROW(1     ,'  3667 ','WARREN    ','OH'),ROW(2     ,'
2948','SHAKER HTS','OH')}
END_EVAL1

print Dumper( $multi_set ), "\n";

You could even define the two functions as below if you simply wanted
the first field for ordering.

sub ROW (@) { return ( shift, [ @_ ] ); }

sub MULTISET (&) {
    my %hash =3D ( shift()->() );
    return [ map { $hash{$_} } sort { $a <=3D> $b } keys %hash ];
}

or

sub MULTISET ($) { # for {} as a hash ref
    my $hash_ref =3D shift;
    return [ map { $hash_ref->{$_} } sort { $a <=3D> $b } keys %
$hash_ref ];
}


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

Date: Thu, 3 Apr 2008 13:02:02 -0700 (PDT)
From: pgodfrin <pgodfrin@gmail.com>
Subject: Creating a 'load simulator' by calling Perl Programs - or Forking?
Message-Id: <05991148-a1d2-4f55-90f7-e66f9e98a4cd@s37g2000prg.googlegroups.com>

Greetings,

I would like to create a 'driver' (simulation) program that calls
existing perl programs, waits for them to complete and provides some
feedback. Ideally I would like to have the driver echo to the screen
that the simulation is still running and perhaps provide some
information. That may be too ambitious, but that is the basic idea.

I have a handful of perl programs that do things - read a database
(kudos to the DBI modules) and output a report, from a few lines to a
few thousand.

Question #1: What is the proper way to execute the perl programs?

I am familiar with exec() and system() and have done this:

  system("sallmr1 -n50000 >/dev/null");
  system("srngmr1 -sr -es -n10000 >/dev/null");
  system("srngmr2 -sr -es -n10000 >/dev/null");

Which executes these three programs sequentially - or by adding '&' at
the end I can execute them at the same time. Of course the 'calling'
program cannot wait for the background tasks because of the shell
return.

Which leads me down the path of fork(). If I were to code the
following:

  for(1..2)
  {
	  if($pid=fork)
	  {
		  # parent
	  }	elsif (defined $pid)
	  {
		  # child
		  exec("sallmr1 -n50000 >/dev/null");
        }	#	end child (elsif)
  }	#	end for loop
  do {  $x=wait; print "$x died\n";} until $x==-1;

Then I would get a pair of runs, and wait until each child dies.

Question #2: Is there a way to echo to the screen that the wait() is
happening and provide some indication of progress?

To clarify this question, I had originally tried:
  do {$x=wait; print ".";} until $x==-1;

Thinking I would get a period printed during the loop. (silly me -
wait only comes back when a child process dies...).

Of course if this is much to complicated a way to so a simulated load,
then so be it - just a plain old fork and wait works fine... And I
could always remove the /dev/null and actually see the called programs
output, which will tell me that it's still running... But I was
curious if there is a more elegant or at least interesting way of
doing this?

thanks,
phil


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

Date: Thu, 3 Apr 2008 23:04:39 +0800
From: "Ela" <ela@yantai.org>
Subject: frustrated in installing modules
Message-Id: <ft2rmb$sla$1@ijustice.itsc.cuhk.edu.hk>

I use a function from GD::Graph::chart

and then it prompts me that no such module exists. Fine, using cpan to 
install that, it says no such a module. back one level, install GD::Graph. 
Ok, it's installed but still error persists. force install helps little. 
Similar errors occur quite often and I'm really frustrated about this. Could 
anybody tell me what's going wrong? 




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

Date: Thu, 3 Apr 2008 08:27:31 -0700 (PDT)
From: smallpond <smallpond@juno.com>
Subject: Re: frustrated in installing modules
Message-Id: <d25ee5eb-bbaf-4b26-926a-ebf6dcbf28ae@8g2000hse.googlegroups.com>

On Apr 3, 11:04 am, "Ela" <e...@yantai.org> wrote:
> I use a function from GD::Graph::chart
>
> and then it prompts me that no such module exists. Fine, using cpan to
> install that, it says no such a module. back one level, install GD::Graph.
> Ok, it's installed but still error persists. force install helps little.
> Similar errors occur quite often and I'm really frustrated about this. Could
> anybody tell me what's going wrong?

I suggest you re-read the documentation:

GD::Graph::chart->new([width,height])

"chart is either bars, lines, points, linespoints, area, mixed or
pie."


It would be nice if when you post, you give some code and the actual
error that you are getting instead of your interpretation.  Makes
it a lot easier to help you.


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

Date: Thu, 3 Apr 2008 23:31:38 +0800
From: "Ela" <ela@yantai.org>
Subject: Re: frustrated in installing modules
Message-Id: <ft2t8u$tee$1@ijustice.itsc.cuhk.edu.hk>

Problem solved... Very, very sorry for causing inconvenience... sorry 




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

Date: Thu, 03 Apr 2008 18:25:31 GMT
From: "A. Sinan Unur" <1usa@llenroc.ude.invalid>
Subject: Re: frustrated in installing modules
Message-Id: <Xns9A7592BD2F518asu1cornelledu@127.0.0.1>

"Ela" <ela@yantai.org> wrote in
news:ft2t8u$tee$1@ijustice.itsc.cuhk.edu.hk: 

> Problem solved... Very, very sorry for causing inconvenience...
> sorry 

No need to be so sorry to have asked for help. However, next time, you 
can improve your chances of being able to help yourself by reading and 
following the suggestions in the clpm guidelines. They are posted here 
regularly (also, see my sig).

Sinan

-- 
A. Sinan Unur <1usa@llenroc.ude.invalid>
(remove .invalid and reverse each component for email address)

comp.lang.perl.misc guidelines on the WWW:
http://www.rehabitation.com/clpmisc/


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

Date: Thu, 03 Apr 2008 09:54:50 -0500
From: Ted Zlatanov <tzz@lifelogs.com>
Subject: Re: mismatch between Perl 5.6 and Perl 5.8 in printing high precision  values.
Message-Id: <86abkb6lad.fsf@lifelogs.com>

On Thu, 3 Apr 2008 01:08:59 +0100 Ben Morrow <ben@morrow.me.uk> wrote: 

BM> I think the stated position is 'perl provides no guarantees about
BM> anything to do with FP'.

Position of who?  

There's Math::BigFloat and Math::BigRat which are at least moderately
useful.

Ted


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

Date: Thu, 3 Apr 2008 23:39:17 +0800
From: "Ela" <ela@yantai.org>
Subject: New errors of export image format
Message-Id: <ft2tn9$thi$1@ijustice.itsc.cuhk.edu.hk>


"smallpond" <smallpond@juno.com> wrote in message 
news:d25ee5eb-bbaf-4b26-926a-ebf6dcbf28ae@8g2000hse.googlegroups.com...
> It would be nice if when you post, you give some code and the actual
> error that you are getting instead of your interpretation.  Makes
> it a lot easier to help you.

The codes are as follows and now the problem becomes "Can't call method 
"png" on an undefined value at plot_ss_b.pl line 34." printing error message 
or not does not lead to great difference... The input file is like this:
==========
9 ~ 20.03
10 E 14.56
11 E 12.16
==========

#!/usr/bin/perl

use GD::Graph;
use GD::Graph::bars;

$filename = $ARGV[0];

open(FP, $filename);

while ($line  = <FP>) {
    @words = split(/ /, $line);
    if ($words[1] =~ /[A-Z]/) {
        push @x, $words[0];
        push @y, $words[2];
    }
}

@data = (@x, @y);

close FP;

print $data[0], $data[1];

my $graph = GD::Graph::bars->new(400, 300) or die GD::Graph->error;

  $graph->set(
          title             => 'B vs SS',
          ) or die $graph->error;

  #open(IMG, ">$filename.gif") or die $!;
  open(IMG, ">$filename.png") or die $!;
  binmode IMG;
  #$gd = $graph->plot(\@data)->gif;
   $graph->plot(\@data)->png or die $graph->error;
  print IMG $gd;
  close IMG;


 




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

Date: Thu, 03 Apr 2008 12:22:03 -0500
From: "J. Gleixner" <glex_no-spam@qwest-spam-no.invalid>
Subject: Re: New errors of export image format
Message-Id: <47f5123c$0$48216$815e3792@news.qwest.net>

Ela wrote:

> The codes are as follows and now the problem becomes "Can't call method 
> "png" on an undefined value at plot_ss_b.pl line 34." printing error message 
> or not does not lead to great difference... The input file is like this:

> ==========
> 9 ~ 20.03
> 10 E 14.56
> 11 E 12.16
> ==========
> 
> #!/usr/bin/perl
> 
> use GD::Graph;
> use GD::Graph::bars;
Missing:

use strict;
use warnings;

> 
> $filename = $ARGV[0];
my $filename = $ARGV[0];
> 
> open(FP, $filename);
And if it fails???..
open( my $fp, '<', $filename ) or die "Can't open $filename: $!";
> 
> while ($line  = <FP>) {
while ( my $line = <FP> ) {
chomp( $line );  # or could chomp $words[2] in if()

>     @words = split(/ /, $line);
>     if ($words[1] =~ /[A-Z]/) {
>         push @x, $words[0];
>         push @y, $words[2];
>     }
> }
> 
> @data = (@x, @y);

This is not the correct data structure. Fix this
and it should work... provided you have the PNG
libraries.


> 
> close FP;
close( $fp );
> 
> print $data[0], $data[1];
This should print ARRAY(...) if @data is correct. Easiest to use
Data::Dumper to print the values;

use Data::Dumper;
print Dumper( @data );

> 
> my $graph = GD::Graph::bars->new(400, 300) or die GD::Graph->error;

What formats can you use?

print 'Supported formats: ', join( ',', $graph->export_format ), "\n";

die "Need PNG libs" unless $graph->can( 'png' );
> 
>   $graph->set(
>           title             => 'B vs SS',
>           ) or die $graph->error;
> 
>   #open(IMG, ">$filename.gif") or die $!;
>   open(IMG, ">$filename.png") or die $!;
>   binmode IMG;
>   #$gd = $graph->plot(\@data)->gif;
>    $graph->plot(\@data)->png or die $graph->error;
>   print IMG $gd;

print IMG $graph->plot(\@data)->png;

or

$graph->plot( \@data );
print IMG $graph->png;

>   close IMG;

Start with the examples in the documentation.  If they work,
then you know it's something in your code.


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

Date: Thu, 03 Apr 2008 18:23:42 GMT
From: "A. Sinan Unur" <1usa@llenroc.ude.invalid>
Subject: Re: New errors of export image format
Message-Id: <Xns9A75926E9413Fasu1cornelledu@127.0.0.1>

"J. Gleixner" <glex_no-spam@qwest-spam-no.invalid> wrote in
news:47f5123c$0$48216$815e3792@news.qwest.net: 

> Ela wrote:
> 
>> $filename = $ARGV[0];
> my $filename = $ARGV[0];

I prefer

my ($filename) = @ARGV;

Then, adding another command line parameter results in only having 
to change the LHS of the statement:

my ($filename, $device) = @ARGV;

Of course, one can only get so much out of positional parameters but 
works for quick and dirty scripts.

Sinan

-- 
A. Sinan Unur <1usa@llenroc.ude.invalid>
(remove .invalid and reverse each component for email address)

comp.lang.perl.misc guidelines on the WWW:
http://www.rehabitation.com/clpmisc/


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

Date: Thu, 3 Apr 2008 06:51:31 -0700 (PDT)
From: Wg <techrepository@gmail.com>
Subject: Problem adding new line !
Message-Id: <1afb96ab-3a7d-4d87-b942-3cab835d620c@q27g2000prf.googlegroups.com>

Hi,

I'm trying to add a new line to a file say "tmp_file1.txt" before
reading into that file. Here tmp_file1.txt is the destination file
into which I'm trying to copy.. Pasting code snippet. Is there
anything that I'm missing out here ..

sub create_tmp_file1()
{

       # Pls note: the function recieve's the file handle of the
source file and passess on the file handle of the #destination file to
the sub routine that is called for inserting new line.. Attempt is to
give sufficient spacing   #between reading from each source file..


	my $inputFile = $_[0];
	my $getLine;
	open (TMP_FH, ">>tmp_file1.txt") or die "Unable to open file
tmp_file1 for writing ..\n";
	print $inputFile."\n";

	&addNewLine(\*TMP_FH);

	while(<$inputFile>){

		$getLine = $_;
		print TMP_FH $getLine;
	}

	$getLine = "\x0C";
	print TMP_FH $getLine;


#	print TMP_FH "\x0c";

	close (TMP_FH);

}

# Function that adds new line character..

sub addNewLine(){

	my $fileName = $_[0];
	my $count = 0;

#	open TEMP_FH, ">>".$fileName or die "Failed opening $outputFile
file ...";

	while($count le 30){
			#print TEMP_FH "\n";
			#print TEMP_FH "  \n";
		print $fileName "  \n";
		$count++;
	}

#	close(TEMP_FH);

}

Any pointer to this would be greatly appreciated..

-Wg


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

Date: Thu, 3 Apr 2008 07:22:19 -0700 (PDT)
From: smallpond <smallpond@juno.com>
Subject: Re: Problem adding new line !
Message-Id: <84b155e9-7c43-496a-bf4b-1835739ff3ac@8g2000hsu.googlegroups.com>

On Apr 3, 9:51 am, Wg <techreposit...@gmail.com> wrote:
> Hi,
>
> I'm trying to add a new line to a file say "tmp_file1.txt" before
> reading into that file. Here tmp_file1.txt is the destination file
> into which I'm trying to copy.. Pasting code snippet. Is there
> anything that I'm missing out here ..
>

You forgot to say "doesn't work" as the complete
explanation of what problem you might be having.




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

Date: Thu, 3 Apr 2008 15:36:04 +0100
From: Ben Morrow <ben@morrow.me.uk>
Subject: Re: Problem adding new line !
Message-Id: <kj6fc5-8i11.ln1@osiris.mauzo.dyndns.org>


Quoth Wg <techrepository@gmail.com>:
> 
> I'm trying to add a new line to a file say "tmp_file1.txt" before
> reading into that file. Here tmp_file1.txt is the destination file
> into which I'm trying to copy.. Pasting code snippet. Is there
> anything that I'm missing out here ..

What's going wrong? It's not clear exactly what you're trying to
achieve, and you haven't told us what the code below is doing wrong. It
appears to be appending the contents of $inputFile, followed by 31 lines
with two spaces, followed by a form-feed character (with no following
newline, so the file is no longer a text file) to tmp_file1.txt.

Some general comments on the code follow, but I doubt they'll solve your
problem.

> sub create_tmp_file1()

You don't want those parens: they don't do what you thing they do. Perl
isn't shell.

    sub create_tmp_file1 {

> {
> 
>        # Pls note: the function recieve's the file handle of the
> source file and passess on the file handle of the #destination file to
> the sub routine that is called for inserting new line.. Attempt is to
> give sufficient spacing   #between reading from each source file..
> 
> 
> 	my $inputFile = $_[0];
> 	my $getLine;

It's generally bad practice to declare variables earlier than you need
them.

> 	open (TMP_FH, ">>tmp_file1.txt") or die "Unable to open file
> tmp_file1 for writing ..\n";

You will find dealing with filehandles much easier if you use the
lexical filehandles introduced in perl 5.6. For a start, you won't need
to mess around with globrefs.

You should use three-arg open: while it doesn't matter in this case,
it's a good habit to get into.

    open(my $TMP_FH, ">>", "tmp_file1.txt")
        or die "...";

> 	print $inputFile."\n";
> 
> 	&addNewLine(\*TMP_FH);

Don't call subs with & unless you know what it does. This may explain
why you got away with the () on your sub declarations...

With lexical filehandles (opened as above) you don't need to use globref
syntax. Just pass the filehandle as it is:

    addNewLine($TMP_FH);

> 	while(<$inputFile>){
> 
> 		$getLine = $_;

It's clearer to assign directly into the right variable. As a bonus, you
don't stomp on the global $_.

    while (my $getLine = <$inputFile>) {

> 		print TMP_FH $getLine;
> 	}
> 
> 	$getLine = "\x0C";
> 	print TMP_FH $getLine;

 ...of course, then $getLine is no longer in scope here. I would just go
back to printing it directly.

    print $TMP_FH "\x0C";

> #	print TMP_FH "\x0c";
> 
> 	close (TMP_FH);

Another benefit of lexical filehandles is that they close for you when
the variable goes out of scope. When you're writing to a file, though,
you should check for errors on close, as any error while writing
(because of a full disk, for instance) will show up as an error on close.
(Of course, if you want to know exactly *what* failed to write, as
opposed to simply dieing with an error, you'll need to check the return
value of print as well.)

> }
> 
> # Function that adds new line character..
> 
> sub addNewLine(){
> 
> 	my $fileName = $_[0];

This is not a file name, but a filehandle. I presume you know this, but
leaving bad variable names in your code is a sure way to confuse
yourself when you come back to it later (not to mention people on Usenet
trying to read your code).

> 	my $count = 0;
> 
> #	open TEMP_FH, ">>".$fileName or die "Failed opening $outputFile
> file ...";
> 
> 	while($count le 30){

It's simpler to write this as a for loop (foreach if you prefer):

    for my $count (0..30) {

Ben



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

Date: Thu, 3 Apr 2008 10:22:32 -0700 (PDT)
From: Wg <techrepository@gmail.com>
Subject: Re: Problem adding new line !
Message-Id: <d2e5e674-8bef-4903-b4d5-5c3bddb9c8b8@q27g2000prf.googlegroups.com>

On Apr 3, 7:36=A0pm, Ben Morrow <b...@morrow.me.uk> wrote:
> Quoth Wg <techreposit...@gmail.com>:
>
>
>
> > I'm trying to add a new line to a file say "tmp_file1.txt" before
> > reading into that file. Here tmp_file1.txt is the destination file
> > into which I'm trying to copy.. Pasting code snippet. Is there
> > anything that I'm missing out here ..
>
> What's going wrong? It's not clear exactly what you're trying to
> achieve, and you haven't told us what the code below is doing wrong. It
> appears to be appending the contents of $inputFile, followed by 31 lines
> with two spaces, followed by a form-feed character (with no following
> newline, so the file is no longer a text file) to tmp_file1.txt.
>
> Some general comments on the code follow, but I doubt they'll solve your
> problem.
>
> > sub create_tmp_file1()
>
> You don't want those parens: they don't do what you thing they do. Perl
> isn't shell.
>
> =A0 =A0 sub create_tmp_file1 {
>
> > {
>
> > =A0 =A0 =A0 =A0# Pls note: the function recieve's the file handle of the=

> > source file and passess on the file handle of the #destination file to
> > the sub routine that is called for inserting new line.. Attempt is to
> > give sufficient spacing =A0 #between reading from each source file..
>
> > =A0 =A0my $inputFile =3D $_[0];
> > =A0 =A0my $getLine;
>
> It's generally bad practice to declare variables earlier than you need
> them.
>
> > =A0 =A0open (TMP_FH, ">>tmp_file1.txt") or die "Unable to open file
> > tmp_file1 for writing ..\n";
>
> You will find dealing with filehandles much easier if you use the
> lexical filehandles introduced in perl 5.6. For a start, you won't need
> to mess around with globrefs.
>
> You should use three-arg open: while it doesn't matter in this case,
> it's a good habit to get into.
>
> =A0 =A0 open(my $TMP_FH, ">>", "tmp_file1.txt")
> =A0 =A0 =A0 =A0 or die "...";
>
> > =A0 =A0print $inputFile."\n";
>
> > =A0 =A0&addNewLine(\*TMP_FH);
>
> Don't call subs with & unless you know what it does. This may explain
> why you got away with the () on your sub declarations...
>
> With lexical filehandles (opened as above) you don't need to use globref
> syntax. Just pass the filehandle as it is:
>
> =A0 =A0 addNewLine($TMP_FH);
>
> > =A0 =A0while(<$inputFile>){
>
> > =A0 =A0 =A0 =A0 =A0 =A0$getLine =3D $_;
>
> It's clearer to assign directly into the right variable. As a bonus, you
> don't stomp on the global $_.
>
> =A0 =A0 while (my $getLine =3D <$inputFile>) {
>
> > =A0 =A0 =A0 =A0 =A0 =A0print TMP_FH $getLine;
> > =A0 =A0}
>
> > =A0 =A0$getLine =3D "\x0C";
> > =A0 =A0print TMP_FH $getLine;
>
> ...of course, then $getLine is no longer in scope here. I would just go
> back to printing it directly.
>
> =A0 =A0 print $TMP_FH "\x0C";
>
> > # =A0print TMP_FH "\x0c";
>
> > =A0 =A0close (TMP_FH);
>
> Another benefit of lexical filehandles is that they close for you when
> the variable goes out of scope. When you're writing to a file, though,
> you should check for errors on close, as any error while writing
> (because of a full disk, for instance) will show up as an error on close.
> (Of course, if you want to know exactly *what* failed to write, as
> opposed to simply dieing with an error, you'll need to check the return
> value of print as well.)
>
> > }
>
> > # Function that adds new line character..
>
> > sub addNewLine(){
>
> > =A0 =A0my $fileName =3D $_[0];
>
> This is not a file name, but a filehandle. I presume you know this, but
> leaving bad variable names in your code is a sure way to confuse
> yourself when you come back to it later (not to mention people on Usenet
> trying to read your code).
>
> > =A0 =A0my $count =3D 0;
>
> > # =A0open TEMP_FH, ">>".$fileName or die "Failed opening $outputFile
> > file ...";
>
> > =A0 =A0while($count le 30){
>
> It's simpler to write this as a for loop (foreach if you prefer):
>
> =A0 =A0 for my $count (0..30) {
>
> Ben

Thanks Ben !

I was trying to insert new line to the destination file between
reading each source file. Follow'd Ben's guidance on this.. Pasting
below the code snippet that worked for me..

sub create_tmp_file1{

	open (my $TMP_FH,">>","tmp_file1.txt") or die "Unable to open file
tmp_file1 for writing ..\n";

	addNewLine($TMP_FH);

	my $inputFile =3D $_[0];
	my $getLine;

	while(<$inputFile>){

		$getLine =3D $_;
		print $TMP_FH $getLine;
	}

	print $TMP_FH "\x0C";

	close ($TMP_FH);

}

sub addNewLine{

	my $fileHandle =3D $_[0];

#	open ($fileHandle, ">>", "tmp_file1.txt") or die "Failed opening
file ...";

	for my $count(0 .. 10){

		print $fileHandle "  \n";

	}

#	close($fileHandle);

}

Thanks Ben for your time and patience..

-Wg


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

Date: Thu, 03 Apr 2008 19:20:40 GMT
From: "John W. Krahn" <someone@example.com>
Subject: Re: Problem adding new line !
Message-Id: <c6aJj.15445$pb5.5725@edtnps89>

Wg wrote:
> 
> I was trying to insert new line to the destination file between
> reading each source file. Follow'd Ben's guidance on this.. Pasting
> below the code snippet that worked for me..
> 
> sub create_tmp_file1{
> 
> 	open (my $TMP_FH,">>","tmp_file1.txt") or die "Unable to open file
> tmp_file1 for writing ..\n";
> 
> 	addNewLine($TMP_FH);
> 
> 	my $inputFile = $_[0];
> 	my $getLine;
> 
> 	while(<$inputFile>){
> 
> 		$getLine = $_;
> 		print $TMP_FH $getLine;
> 	}
> 
> 	print $TMP_FH "\x0C";
> 
> 	close ($TMP_FH);
> 
> }
> 
> sub addNewLine{
> 
> 	my $fileHandle = $_[0];
> 
> #	open ($fileHandle, ">>", "tmp_file1.txt") or die "Failed opening
> file ...";

You had already opened the filehandle in create_tmp_file1() above so you 
don't have to open it again.


> 	for my $count(0 .. 10){
> 
> 		print $fileHandle "  \n";
> 
> 	}

Or more simply:

         print $fileHandle "  \n" x 11;

Or just replace the line:

  	addNewLine($TMP_FH);

in create_tmp_file1() above with the line:

         print $TMP_FH "  \n" x 11;


> #	close($fileHandle);
> 
> }


John
-- 
Perl isn't a toolbox, but a small machine shop where you
can special-order certain sorts of tools at low cost and
in short order.                            -- Larry Wall


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

Date: 03 Apr 2008 12:25:35 -0400
From: Charlton Wilbur <cwilbur@chromatico.net>
Subject: Re: RE Perl Pattern matching
Message-Id: <87ve2yj474.fsf@mithril.chromatico.net>

>>>>> "BB" == Ben Bullock <benkasminbullock@gmail.com> writes:

    BB> On Wed, 02 Apr 2008 10:53:34 -0500, Chris Mattern wrote:
    >> You're trying to parse XML with regular expressions.  Don't do
    >> that.  Perl has a large selection of excellent modules for
    >> processing XML. Use them.

    BB> Chris, do you talk like that to people in real life, or is it
    BB> just the internet?

When you've said the same thing over and over to people who aren't
getting it, there is a clear temptation to speak slowly, with short
sentences and short words.

Charlton


-- 
Charlton Wilbur
cwilbur@chromatico.net


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

Date: Thu, 03 Apr 2008 12:29:50 -0700
From: David Filmer <usenet@davidfilmer.com>
Subject: Re: Spelling suggestions for common words - ispell, etc.
Message-Id: <MbWdncjIlYhgsmja4p2dnAA@giganews.com>

sftriman wrote:
> get a list of suggested words for a misspelled word.  Or better, "the"
> most likely intended word for a misspelled word.

Ever notice that Google does a pretty good job of that?  So consider 
Net::Google::Spelling:
http://search.cpan.org/~bstilwell/Net-Google-1.0.1/lib/Net/Google/Spelling.pm

-- 
David Filmer (http://DavidFilmer.com)


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

Date: Thu, 03 Apr 2008 21:34:46 +0200
From: Joost Diepenmaat <joost@zeekat.nl>
Subject: Re: Spelling suggestions for common words - ispell, etc.
Message-Id: <87iqyy20mh.fsf@zeekat.nl>

sftriman <ironmanda@yahoo.com> writes:

> I am looking for a way to, without custom defining a dictionary, to
> get a list of suggested words for a misspelled word.  Or better, "the"
> most likely intended word for a misspelled word.

You may find this article interesting: 
http://norvig.com/spell-correct.html

You still need a list of "good" words, of course.

-- 
Joost Diepenmaat | blog: http://joost.zeekat.nl/ | work: http://zeekat.nl/


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

Date: Thu, 3 Apr 2008 09:09:33 -0700 (PDT)
From: Adam.L.MacKinnon@gmail.com
Subject: Win32::OLE "Member not found"
Message-Id: <4c13eec5-c947-4228-9e18-9ecfa8cdaf8d@d62g2000hsf.googlegroups.com>

Hi,

Am attempting to run the simple script as follows (sourced from:
http://techtasks.com/code/viewbookcode/443)

use strict;
use warnings;
use Data::Dumper;
use Win32::OLE;
$Win32::OLE::Warn = 3;

#use lib 'H:\dev\perl\NSLC-Store-Mgmt\lib';
#use NSLC::Store::Mgmt;

my %args;

$args{name} = 'TESTVAR';
$args{value} = 'TESTVALUE';
$args{target} = '.';

set_env_var(\%args);

sub set_env_var {
    my ($args,) = @_;
    my $strVarName  = $args->{name};
    my $strVarValue = $args->{value};
    my $strComputer = $args->{target};

    my $objVarClass = Win32::OLE->GetObject('winmgmts://' .
$strComputer . '/root/cimv2:Win32_Environment');
    my $objVar = $objVarClass->SpawnInstanceobjVar->Name eq
$strVarName;
    $objVar->{VariableValue} = $strVarValue;
    $objVar->{UserName} = '<SYSTEM>';
    $objVar->PutWScript->Echo('Created environment variable ' .
$strVarName);
}

The following message is returned.
retrying default method at C:/Perl/site/lib/Win32/OLE/Lite.pm line
156.
Win32::OLE(0.1403) error 0x80020003: "Member not found"
    in METHOD/PROPERTYGET "" at H:\dev\perl\test\setenv.pl  line 28
shell returned 9

I am completely new to using perl in a windows environment and am not
sure where to start debugging.  I have read all that I can via module
docs and web information but am still having no luck.
As far as I can tell, syntactically the script is fine but I am not
sure how the guts of $objVarClass->SpawnInstanceobjVar->Name eq
$strVarName; is working.  I am running this on XP pro using activeperl
5.8.8(820).

Any insight would be appreciated.

Thanks


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

Date: 6 Apr 2001 21:33:47 GMT (Last modified)
From: Perl-Users-Request@ruby.oce.orst.edu (Perl-Users-Digest Admin) 
Subject: Digest Administrivia (Last modified: 6 Apr 01)
Message-Id: <null>


Administrivia:

#The Perl-Users Digest is a retransmission of the USENET newsgroup
#comp.lang.perl.misc.  For subscription or unsubscription requests, send
#the single line:
#
#	subscribe perl-users
#or:
#	unsubscribe perl-users
#
#to almanac@ruby.oce.orst.edu.  

NOTE: due to the current flood of worm email banging on ruby, the smtp
server on ruby has been shut off until further notice. 

To submit articles to comp.lang.perl.announce, send your article to
clpa@perl.com.

#To request back copies (available for a week or so), send your request
#to almanac@ruby.oce.orst.edu with the command "send perl-users x.y",
#where x is the volume number and y is the issue number.

#For other requests pertaining to the digest, send mail to
#perl-users-request@ruby.oce.orst.edu. Do not waste your time or mine
#sending perl questions to the -request address, I don't have time to
#answer them even if I did know the answer.


------------------------------
End of Perl-Users Digest V11 Issue 1418
***************************************


home help back first fref pref prev next nref lref last post