Re: When to use anonymous references

2010-05-01 Thread Peter Scott
On Wed, 28 Apr 2010 01:16:16 -0400, Uri Guttman wrote:

>> "PS" == Peter Scott  writes:
> 
>   PS> On Mon, 26 Apr 2010 22:16:27 +0800, Tim Bowden wrote:
>   >> I've just realised I almost never use named arrays or hashes
>   >> anymore. It's almost always anonymous references instead.  That
>   >> lead me to wonder what criteria experienced perl hackers have as to
>   >> when to use a named array or hash, and when to start with an
>   >> anonymous ref instead.  My very informal criteria tends to be to
>   >> use an anonymous ref from the start if I'm going to be passing it
>   >> to a sub, and a named array or hash otherwise.  I've found the
>   >> former to be much more common.  Thoughts?
> 
>   PS> I create arrays and hashes by default, not references to anonymous
>   PS> versions.  I'd sooner not be putting arrows in unnecessarily.  I
>   can PS> always enreference an aggregate in the call to a sub.
> 
> my choice is usually based on usage. if i am building up data
> structures, the members are almost always anon refs - no need to have
> named vars for them.

Right.  I should have said that I don't create named references, most of 
the time, but anon references as part of a data structure, sure.  In 
other words, I very rarely do

my $some_ref = \anything or [anything] or {anything}

as in the original post.

-- 
Peter Scott
http://www.perlmedic.com/ http://www.perldebugged.com/
http://www.informit.com/store/product.aspx?isbn=0137001274
http://www.oreillyschool.com/courses/perl1/

-- 
To unsubscribe, e-mail: beginners-unsubscr...@perl.org
For additional commands, e-mail: beginners-h...@perl.org
http://learn.perl.org/




Re: Interactive shell in Perl

2010-05-01 Thread Parag Kalra
I installed psh but getting following error after launching it:

Cannot find termcap: TERM not set at C:\perl\lib/Term/ReadLine.pm line 351

Cheers,
Parag



On Wed, Apr 28, 2010 at 7:45 AM, John W. Krahn  wrote:

> Parag Kalra wrote:
>
>> Hey All,
>>
>
> Hello,
>
>
>  Wanted to know if Perl has any interactive shell (just like Python, Bash,
>> Ruby etc have) by any chance. And if yes how do we invoke that.
>>
>
> perldoc -q "Is there a Perl shell"
>
>
> John
> --
> The programmer is fighting against the two most
> destructive forces in the universe: entropy and
> human stupidity.   -- Damian Conway
>
>
> --
> To unsubscribe, e-mail: beginners-unsubscr...@perl.org
> For additional commands, e-mail: beginners-h...@perl.org
> http://learn.perl.org/
>
>
>


Re: Redirecting the Output and Error of Perl script

2010-05-01 Thread Shawn H Corey

Parag Kalra wrote:

Thanks all...

I was printing in normal fashion. I should have used something lik:

print STDERR "stderr\n";

as suggested by all.



Perhaps you should be using warn and die:

warn "This appears on STDERR\n";


--
Just my 0.0002 million dollars worth,
  Shawn

Programming is as much about organization and communication
as it is about coding.

I like Perl; it's the only language where you can bless your
thingy.

Eliminate software piracy:  use only FLOSS.

--
To unsubscribe, e-mail: beginners-unsubscr...@perl.org
For additional commands, e-mail: beginners-h...@perl.org
http://learn.perl.org/




Re: Redirecting the Output and Error of Perl script

2010-05-01 Thread Parag Kalra
Thanks all...

I was printing in normal fashion. I should have used something lik:

print STDERR "stderr\n";

as suggested by all.

Cheers,
Parag



On Sat, May 1, 2010 at 1:55 AM, Philip Potter wrote:

> On 30 April 2010 18:45, Parag Kalra  wrote:
> > Hey All,
> >
> > I am trying to execute a Perl via shell script. I want to redirect output
> of
> > Perl script to one file and error occured (if any) to other file.
> >
> > This is the snippet from my shell script:
> >
> > perl output_error.pl 1>> Report.log 2>>Error.log
> >
>
> What you have written works for me. I think your error is somewhere else.
>
> $ cat foo.pl
> #!perl
>
> print "stdout\n";
> print STDERR "stderr\n";
>
> $ perl foo.pl 1>> out 2>> err
> $ cat out
> stdout
> $ cat err
> stderr
>
> Note that >> appends to the end of a file, while > replaces the file.
>
> Phil
>


Re: testing if divisible by?

2010-05-01 Thread Uri Guttman
> "JLP" == Jamie L Penman-Smithson  writes:

  JLP> On Sat, 2010-05-01 at 07:15 -0400, Paul wrote:
  >> Hello all.  How can I test to see if a number is divisible by say, 40? 

  JLP> Use the modulo operator:

  JLP> my $a = 40;
  JLP> my $b = 1;

  JLP> if ($a % $b == 0) {

no need for the == 0 if you invert the test with unless or change the
print text.

  JLP> print "$b is divisible by $a\n";
  JLP> }

uri

-- 
Uri Guttman  --  u...@stemsystems.com    http://www.sysarch.com --
-  Perl Code Review , Architecture, Development, Training, Support --
-  Gourmet Hot Cocoa Mix    http://bestfriendscocoa.com -

-- 
To unsubscribe, e-mail: beginners-unsubscr...@perl.org
For additional commands, e-mail: beginners-h...@perl.org
http://learn.perl.org/




Re: testing if divisible by?

2010-05-01 Thread Jamie L. Penman-Smithson
On Sat, 2010-05-01 at 07:15 -0400, Paul wrote:
> Hello all.  How can I test to see if a number is divisible by say, 40? 

Use the modulo operator:

my $a = 40;
my $b = 1;

if ($a % $b == 0) {
print "$b is divisible by $a\n";
}

-j


-- 
To unsubscribe, e-mail: beginners-unsubscr...@perl.org
For additional commands, e-mail: beginners-h...@perl.org
http://learn.perl.org/




Re: testing if divisible by?

2010-05-01 Thread Philip Potter
On 1 May 2010 12:15, Paul  wrote:
> Hello all.  How can I test to see if a number is divisible by say, 40?
> Thanks.

Use the modulo operator %. Given integers $x and $y, the expression $x
% $y gives the remainder when $x is divided by $y. As a result, if
(and only if) $x is exactly divisible by $y, $x % $y is equal to 0.

#!perl
use 5.010; # for 'say'

say 5 % 2;
say 6 % 2;
say 7 % 2;

say 79 % 40;
say 80 % 40;
say 81 % 40;

For more information, see
http://perldoc.perl.org/perlop.html#Multiplicative-Operators

Phil

--
To unsubscribe, e-mail: beginners-unsubscr...@perl.org
For additional commands, e-mail: beginners-h...@perl.org
http://learn.perl.org/




Re: testing if divisible by?

2010-05-01 Thread Shawn H Corey

Paul wrote:
Hello all.  How can I test to see if a number is divisible by say, 40? 
Thanks.





See `perldoc perlop` and search for /Multiplicative Operators/  Read the 
part about the % operator.



--
Just my 0.0002 million dollars worth,
  Shawn

Programming is as much about organization and communication
as it is about coding.

I like Perl; it's the only language where you can bless your
thingy.

Eliminate software piracy:  use only FLOSS.

--
To unsubscribe, e-mail: beginners-unsubscr...@perl.org
For additional commands, e-mail: beginners-h...@perl.org
http://learn.perl.org/




testing if divisible by?

2010-05-01 Thread Paul
Hello all.  How can I test to see if a number is divisible by say, 40? 
Thanks.


-- 
To unsubscribe, e-mail: beginners-unsubscr...@perl.org
For additional commands, e-mail: beginners-h...@perl.org
http://learn.perl.org/




Re: Redirecting the Output and Error of Perl script

2010-05-01 Thread Philip Potter
On 30 April 2010 18:45, Parag Kalra  wrote:
> Hey All,
>
> I am trying to execute a Perl via shell script. I want to redirect output of
> Perl script to one file and error occured (if any) to other file.
>
> This is the snippet from my shell script:
>
> perl output_error.pl 1>> Report.log 2>>Error.log
>

What you have written works for me. I think your error is somewhere else.

$ cat foo.pl
#!perl

print "stdout\n";
print STDERR "stderr\n";

$ perl foo.pl 1>> out 2>> err
$ cat out
stdout
$ cat err
stderr

Note that >> appends to the end of a file, while > replaces the file.

Phil

-- 
To unsubscribe, e-mail: beginners-unsubscr...@perl.org
For additional commands, e-mail: beginners-h...@perl.org
http://learn.perl.org/