Re: a condition

2012-08-25 Thread Alan Haggai Alavi
Hello Li,

The `notall` function of `List::MoreUtils`
(https://metacpan.org/module/List::MoreUtils) can be made use of along
with Perl's `grep` function:

#!/usr/bin/env perl

use strict;
use warnings;

use List::MoreUtils qw( notall );

my @array = (
'AB AB AB AB AB',
'AB AC AB AB AB',
'AB AC AD AB AB',
);

@array = grep {
my @elems = split /\s/;  # Split into elements on whitespace
notall { $elems[0] eq $_ } @elems;  # Check if every element is
equal to the first element
} @array;

Without using `List::MoreUtils`:

@array = grep {
my $select = 0;
for ( my @elems = split /\s/ ) {
if ( $elems[0] ne $_ ) {
$select = 1;
}
}
    $select;
} @array;


Regards,
Alan Haggai Alavi.
--
The difference makes the difference

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




Re: subroutine

2012-08-17 Thread Alan Haggai Alavi
Hello Chris,

> Can this subroutine be better written?
> I am getting the following erros:
>
> Use of uninitialized value $y in subtraction (-) at form.pl line 52.
> Use of uninitialized value $y in addition (+) at form.pl line 52.
>
> sub avg_az {
>   my($x, $y) = shift(@_);

In the above line, `shift` will return just the first element from the
@_ array. $y will therefore be undefined. The line should be rewritten
as:
my ( $x, $y ) = @_;

Relevant documentation: `perldoc -f shift` or
http://perldoc.perl.org/functions/shift.html

Regards,
Alan Haggai Alavi.
-- 
The difference makes the difference

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




Re: In search of a list class with unusual accessors

2011-10-19 Thread Alan Haggai Alavi

Hello David,


I am looking for a class that stores zero or more items (e.g. a list)
and that provides accessors that accept and return scalar, list, and/or
array references depending upon context and object content (similar to
CGI.pm, but not exactly the same):


The `wantarray` function can be made use of. It helps in determining the 
context.


#!/usr/bin/perl

use strict;
use warnings;

package WishfulThinkingListClass;

sub new {
return bless [], __PACKAGE__;
}

sub set {
my ( $self, @values ) = @_;
@$self = @values;

return;
}

sub get {
my $self = shift;

if (wantarray) {
return @$self;
}
else {
if ( @$self > 1 ) {
return [@$self];
}
return $self->[0];
}
}

package main;

use Test::More 'tests' => 4;

my $obj = WishfulThinkingListClass->new();

$obj->set('foo');
my $value = $obj->get();
is( $value, 'foo', '$value = foo' );

my @values = $obj->get();
ok( eq_array( \@values, ['foo'] ), '@values = (foo)' );

$obj->set( 'bar', 'baz' );
$value = $obj->get();
ok( eq_array( $value, [ 'bar', 'baz' ] ), '$value = [ "bar", "baz" ]' );

@values = $obj->get();
ok( eq_array( \@values, [ 'bar', 'baz' ] ), '@values = ( "bar", "baz" )' );

__END__

Regards,
Alan Haggai Alavi.
--
The difference makes the difference.

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




Re: GUI Library

2011-09-28 Thread Alan Haggai Alavi

On 09/28/11 16:29, Francisco Rivas wrote:

Hello, I am planning to write a very small stand alone application to write
some file and I would like to know which is the best/recommended GUI library
for Perl. I have read about wxPerl, GTK2, PerlQT4 and even Tk, but I would
like to know what people recommend from their experience.

Thank you very very much in advance for your time and comments. Have a very
nice day.



Hello, Francisco,

Padre, the Perl IDE, uses wxPerl and is under active development. The 
latest Wx was released on 06th of June 2011. I recommend it.


Regards,
Alan Haggai Alavi.
--
The difference makes the difference.

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




Re: Good resources on CGI programming with Perl

2011-09-08 Thread Alan Haggai Alavi

Hello Parag,

> Could some please suggest any good online resources on learning CGI
> programming with Perl

Curtis "Ovid" Poe's CGI course is popular:
http://web.archive.org/web/20070709150107/http://users.easystreet.com/ovid/cgi_course/

Regards,
Alan Haggai Alavi.
--
The difference makes the difference.

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




Re: GUI Module

2011-08-23 Thread Alan Haggai Alavi
Hello Emeka,

> I am thinking of check out GUI ... so I would need to know where to start
> off. Is there a GUI module with Perl? Or am I going to pull one from web?

Check out WxPerl. Padre, the Perl IDE, uses WxPerl for its GUI.

You will have to install `Wx` from CPAN.

Regards,
Alan Haggai Alavi.
-- 
The difference makes the difference.

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




Re: loop break condition

2011-08-22 Thread Alan Haggai Alavi
Hello Shlomi,

> It's a good idea to always use "last LABEL;" instead of "last;" (as well as
> "next LABEL;" etc. in case more loops are added in between.
> ⋮
> http://perl-begin.org/tutorials/bad-elements/#flow-stmts-without-labels

Now I understand why it is always good to label loops that use `last`, `next` 
or `redo`.

Thank you. :-)

Regards,
Alan Haggai Alavi.
-- 
The difference makes the difference.

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




Re: loop break condition

2011-08-22 Thread Alan Haggai Alavi
Hello Anant,

> i want to input some numbers via  in while loop.And loop should be
> broken if any nonnumeric character is entered.So how it can be checked.
> 
> 
> .
> my @ln;
> my $i=0;
> print"Give line numbers you want to put into array.\n";
> while(1){
>  $ln[$i]=;
>  chomp $ln[$i];
>  if($ln[$i] =~ /\D/){
>   print"Its not numeric value.\n";
>   $i--;
>   last;
>  }
>  $i++;
> }
> .

In the above program, `$i` is mostly useless. The length of the array can 
easily be found out by using `scalar @ln`; Perl's `push` function can be used 
for pushing values into the array. There is no need for an index. The program 
can be rewritten as:

use strict;
use warnings;

my @numbers;
print "Enter numbers:\n";
while (1) {
chomp( my $number =  );
if ( $number =~ /\D/ ) {
print "$number is not a numeric value.\n";
last;
}
else {
push @numbers, $number;
}
}


> One more query:-
> HOW TO REMOVE ANY ELEMENT FROM AN ARRAY.
> I mean if i have allocated till arr[5]. Now I want to remove the value
> arr[4] and arr[5]. So how it can be done so that $#arr would tell 3.

You can use the `splice` function (read: `perldoc -f splice`) for this:

splice @array, 4, 2;


Regards,
Alan Haggai Alavi.
-- 
The difference makes the difference.

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




Re: searching the array

2011-08-22 Thread Alan Haggai Alavi
Hello Anant,

Please read:

perldoc -q 'certain element is contained in a list or array'

or

http://bit.ly/o9uKat

Regards,
Alan Haggai Alavi.
-- 
The difference makes the difference.

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




Re: searching the array

2011-08-21 Thread Alan Haggai Alavi
Hello Anant,

> I want to search whether a scalar '$a' contains any one of value of an
> array '@arr'.
> How it may be done?

If you are using perl v5.010 or later, you can use the smart match operator 
(~~):

use 5.010;

use strict;
use warnings;

my @array = qw( foo bar quux );
my $item = 'bar';

if ( $item ~~ @array ) {
say "Item found: $item";
}

However, if you have an older perl, you can use List::Util's (which is a core 
module since perl v5.7.3) `first` subroutine:

use strict;
use warnings;

use List::Util qw( first );

my @array = qw( foo bar quux );
my $item = 'bar';

if ( first { $item eq $_ } @array ) {
print "Item found: $item\n";
}

Regards,
Alan Haggai Alavi.
-- 
The difference makes the difference.

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




Re: Useless use of private variable

2011-08-20 Thread Alan Haggai Alavi
Hello Ron,

> for($i; $i < $n; $i++)

When Perl evaluates the initialiser of the for loop, it just sees a `$i`. 
There are no effects for such a statement. Hence the warning. For getting more 
details about warnings, you can use the diagnostics pragma. (See `perldoc 
diagnostics`)

Since you have already initialised $i to 0 (my $i = 0;), you could omit the 
initialiser of the for loop:

for ( ; $i < $n; $i++ )

Otherwise, as is normal, you can use the for loop's initialiser section to 
declare and then initialise $i to 0:

for ( my $i = 0; $i < $n; $i++ )

Your program can be rewritten as:

print join ', ', 0 .. 7;

Regards,
Alan Haggai Alavi.
-- 
The difference makes the difference.

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




Re: Spidering

2011-08-01 Thread Alan Haggai Alavi
Hello,

> Hi everyone i am a  beginer for Perl can you give me a psedocode and a
> sample code for a spider program.It will be helpful in understanding web
> interfaces.Thank you

Check out WWW::Mechanize - http://search.cpan.org/perldoc?WWW::Mechanize
The SYNOPSIS section will help you get started.

Regards,
Alan Haggai Alavi.
-- 
The difference makes the difference.

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




Re: perl's -M

2011-07-22 Thread Alan Haggai Alavi
Hi Feng,

> What's the meaning of Perl's "-M" operator?

`-M` is a command switch. It is used to load a module and is equivalent to 
`use`-ing a module within the script. `-M` is different from `-m` in that the 
former executes `import` function of the module whereas the latter does not 
import any function except for the ones that have been explicitly listed with 
the command switch.

> which perldoc document is it get descripted in?

Command switches are documented in `perlrun`.

Regards,
Alan Haggai Alavi.
-- 
The difference makes the difference.

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




Re: very starting help

2011-07-17 Thread Alan Haggai Alavi
Hello Anant,

#!/usr/bin/perl is a *shebang* and is useful only in unix-like systems where 
it refers to the location of the interpreter. Under other systems the 
interpreter ignores this line as a comment. Shebang lines are useful to 
execute a script directly without having to specify the interpreter.

Consider a script named main.pl which can be executed under unix-like systems 
as:

perl main.pl

or

./main.pl  # system checks the shebang line for the interpreter to use

For more information: http://en.wikipedia.org/wiki/Shebang_(Unix)

Regards,
Alan Haggai Alavi.
-- 
The difference makes the difference.

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




Re: Using $variable outside a foreach loop

2011-06-03 Thread Alan Haggai Alavi
Hello,

>   foreach my $name (split (/, */, $names)) {

Here, the scope of $name is limited to the foreach loop and not outside it. 
So, you will have to declare the variable again for use outside the loop.

Regards,
Alan Haggai Alavi.
-- 
The difference makes the difference.

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




Re: instal

2011-05-22 Thread Alan Haggai Alavi
On Monday 23 May 2011 09:23:35 Gang Cheng wrote:
> hi,
> 
> I downloaded a perl but I can't instal it said my cpu don't surport this
> instal packet,
> my cpu is i5 with win7 os. how can I instal
> thank you.


Hello,

Which installation package did you try to install?

You may try installing Strawberry Perl - http://strawberryperl.com/

Regards,
Alan Haggai Alavi.
-- 
The difference makes the difference.

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




Re: perl interview questions

2011-04-20 Thread Alan Haggai Alavi

Hello Jyoti,


Please give me any link or any tutorial which will be helpful for
preparation of PERL interview.


Please read `perldoc perlfaq` (http://perldoc.perl.org/perlfaq.html). It
is a collection of frequently asked questions which will certainly help
you at an interview.

Regards,
Alan Haggai Alavi.
--
The difference makes the difference

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




Re: Dynamic replacement of the variable

2011-04-19 Thread Alan Haggai Alavi

Hello friends in the list,

I did not want to reply, however, I have now been forced to reply.

On 04/19/2011 05:26 PM, Jenda Krynicky wrote:

Try Alcoholics Anonymous. This is not a post-traumatic mutual support
group, this is a technical mailing list! If you can't handle a terse
and to the point reply, you should change the profession and try to
find nicer talking people in the humanities. The catch is that the
emails will start with a greeting, continue with a compliment, use
soft words ... and be empty, empty, empty.


A 'Technical mailing-list' does not mean that the posts are posted/read 
by bots! Posts are posted/read by humans who have feelings and can get 
hurt. Statements like the ones quoted above do more harm than good.


On 04/19/2011 05:26 PM, Jenda Krynicky wrote:

As it is, those people should not be doing anything technical in the
first place. The compiler will not start with a greeting and
compliment their hairstyle either.


No one is born a programmer; nor does anyone become a perfectionist 
overnight. Perl might even be some people's first attempt at learning a 
programming language. Quoting Learning Perl: "… we're pleased that we've 
had many reports of people successfully picking up [Learning Perl] and 
grasping Perl as their first programming language …". This list is 
focused on such people. Beginners! We should encourage them and grow the 
community rather than be rude and let them search for 'green pastures'.


For a language to survive, there has to be a thriving community of 
users. A mailing-list that welcomes new users and assists them is what I 
call a 'healthy mailing-list'. Such lists will increase user 
participation and eventually lead to the list being 'useful' to the 
posters as well as to the community.


Flaming is __HARM__ done to the community. No one enjoys it. It is the 
best way to be destructive!


One of my personal experiences:
I once posted an answer here (which happened to be wrong) and I had 
included a sentence: "Hope it is clear now." at the bottom of my 
message. However, a public reply that I got included (other than some 
useful corrections), a reply to the above sentence: "No, nothing is 
clear from those answers." which was an avoidable, unnecessary quote. If 
the replier had appended a smiley :-) to the sentence,  I would have 
certainly considered it humorous. If you are into pun, or play with 
words, consider using smileys as this list is followed by people from 
different nations, backgrounds, cultures and native languages. Most (if 
not all) are able to understand smileys. Not everyone's first language 
is English. It is better not to be ambiguous.


In my humble opinion, for rules like quoting e-mails, using/not using 
line numbers, indenting, et cetera, a wiki page should be created which 
could then be pointed to when needed. If anyone is interested, please 
let me know so that we can build one.


As an aside: I am sorry if any uneasiness was caused by my statements. 
This was inevitable.


A proverb for the thoughtful: "Prevention is better than cure".

Regards,
Alan Haggai Alavi.
--
The difference makes the difference

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




Re: Perl source code beautifier

2011-04-18 Thread Alan Haggai Alavi

Hello Bruno,


I'm looking for a command line tool for Perl source code beautifier.


Have a look at Perl::Tidy. It also includes a script named `perltidy`
which can be run from the command-line.

Regards,
Alan Haggai Alavi.
--
The difference makes the difference

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




Re: WMI

2011-04-16 Thread Alan Haggai Alavi

Hello Mike,


Sure enough the module is gone and I can't find it
in ActiveState ppm.


It is not found in CPAN either.

Regards,
Alan Haggai Alavi.
--
The difference makes the difference

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




Re: format output from system command

2011-04-15 Thread Alan Haggai Alavi

Hello Marc,


What about writing it like this:

open ('FILEOUT', '>>', 'cmdout') ||die "cant open cmdout: $! \n";

Is that O.K.?


You are still using a bareword filehandle.

Regards,
Alan Haggai Alavi.
--
The difference makes the difference

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




Re: Help using cgi

2011-04-13 Thread Alan Haggai Alavi

Hello Prashant,


Thanx alan..


You are welcome.


please suggest the steps to configure my web server.


It depends on which web server you are using. You will probably find a 
cgi-bin directory (in Debian/Ubuntu, Apache's cgi-bin is at 
/usr/lib/cgi-bin/) which is configured to serve CGI scripts. Else, you 
will have to configure the web server to allow another directory to 
serve CGI scripts and copy the script there.


Regards,
Alan Haggai Alavi.
--
The difference makes the difference

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




Re: Help using cgi

2011-04-12 Thread Alan Haggai Alavi

Hello Prashant,


Yesterday i tried a "Hello world" program in perl using cgi script
on a windows platform.


Check out the CGI module on CPAN.



3. opened it with my web browser.

but now instead of giving the output it just shows the original
source code. please help! regards


You have to configure your web server to execute CGI scripts.

Regards,
Alan Haggai Alavi.
--
The difference makes the difference

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




Re: trouble matching words with parentheses using grep

2011-04-09 Thread Alan Haggai Alavi

Hello Mariano,


use List::MoreUtils qw( any each_array );
I was experimenting and forgot to take off `each_array` from the import 
list. `each_array` is not used in the alternative solution and is hence 
not required.


Regards,
Alan Haggai Alavi.
--
The difference makes the difference

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




Re: trouble matching words with parentheses using grep

2011-04-09 Thread Alan Haggai Alavi

Hello Mariano,


I realize that there may be a number of ways to do what I need to do
(most of them better, I bet), and I'd love to learn about them. But
now I'm mostly curious about why grep// cannot "see" words with
parentheses in either (or both lists). I suspect the trick may be
somehow escaping the (), but I tried a number of ways of doing that to
no avail.


Characters having specific meanings in regular expressions have to be 
escaped. You could either use the quotemeta function or enclose the 
regular expression within \Q and \E:


grep /^ \Q $array1[$ctr1] \E $/x, @array2;

Some comments about the code:


#!usr/bin/perl

For increased portability, use the shebang #!/usr/bin/env perl


use warnings;

Also use strict;.


$path1 =; chomp $path1;

Declare variables before they are used.


open (INPUT1, "$path1"); open (INPUT2, "$path2"); open (INPUT3, "$path3");

Try to use the 3-argument version of open.


my ($array1,$array2,$in1and2);

Avoid naming scalars and arrays (or hashes) the same.

An alternative solution:

=pod code

#!/usr/bin/env perl

use strict;
use warnings;

use File::Slurp qw( slurp );
use List::MoreUtils qw( any each_array );

my %path;
print "Enter path to list 1: ";
chomp( $path{'list_1'} =  );
print "Enter path to list 2: ";
chomp( $path{'list_2'} =  );

chomp( my @list_1 = slurp( $path{'list_1'} ) );
chomp( my @list_2 = slurp( $path{'list_2'} ) );

my @common_list;

for my $word (@list_1) {
any { $_ eq $word } @list_2 and push @common_list, $_;
}

printf "in 1 = %d
in 2 = %d
in 1 and 2 = %d\n", scalar @list_1, scalar @list_2, scalar @common_list;

=cut

> Any help will be greatly appreciated! And as usual, if you ever have
> questions about molecular biology and genetics, fire away - I'd love
> to pay the favor back.

Thank you.

Hope this message helps. :-)

Regards,
Alan Haggai Alavi.
--
The difference makes the difference

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




Re: Select equivalent in perl

2011-04-07 Thread Alan Haggai Alavi

Hello Balaji,


I have been using shell script for my admin work and recently decided to use
perl fo all my automation. So proud I did that.


Nice to know that you have decided to use Perl.


Quick question:  I have been using "Select" function in shell to present
menu to users. Do we have a "select" equivalent in perl? Or if I have a list
of names in an array what is the best way to present them in a menu and
prompt the user to select one from the list?


The task is very easy to implement using IO::Prompt:

=pod code

use IO::Prompt;

my @names = qw( foo bar baz qux );
my $selected_name = prompt 'Please select one name: ', -menu => \@names;

print "Selected name: $selected_name\n";

=cut code

Regards,
Alan Haggai Alavi.
--
The difference makes the difference

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




Re: assigning hash to a scalar

2011-03-26 Thread Alan Haggai Alavi

Hi Sunita,


Thanks Alan . I had got this piece of info from google but I do not
understand clearly what it wants to define . It would be good  , if
you can explain bit more .

You are welcome.

The numbers are dependent on the internal hashing algorithm used by perl
of which I am unaware of.

Hopefully the article: "How Hashes Really Work" can help you understand 
better.

- http://www.perl.com/pub/2002/10/01/hashes.html

Regards,
Alan Haggai Alavi.
--
The difference makes the difference

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




Re: assigning hash to a scalar

2011-03-26 Thread Alan Haggai Alavi

Hi Sunita,


$var = %input;
…
Output : 3/8-->  What does this output  mean ?

You are evaluating a hash in a scalar context.

Quoting perldata:

If you evaluate a hash in scalar context, it returns false if the hash
is empty.  If there are any key/value pairs, it returns true; more
precisely, the value returned is a string consisting of the number of
used buckets and the number of allocated buckets, separated by a slash.
 This is pretty much useful only to find out whether Perl's internal
hashing algorithm is performing poorly on your data set.  For example,
you stick 10,000 things in a hash, but evaluating %HASH in scalar
context reveals "1/16", which means only one out of sixteen buckets has
been touched, and presumably contains all 10,000 of your items.  This
isn't supposed to happen.  If a tied hash is evaluated in scalar
context, a fatal error will result, since this bucket usage information
is currently not available for tied hashes.

Regards,
Alan Haggai Alavi.
--
The difference makes the difference

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




Re: Printing Bash and Kernel Version numbers using Perl

2011-03-12 Thread Alan Haggai Alavi

Hello Parag,


Vern Nice. Completely impressed. But I thought Perl might have some
internal variable at least for Kernel version. But anyways this work for
me too.


`Config` module's `config_re` function can be used:

=pod code

use Config 'config_re';

my ($os_version) = config_re('^osvers');
$os_version =~ s/^ osvers= | '//gx;
print $os_version;

=cut

Regards,
Alan Haggai Alavi.
--
The difference makes the difference

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




Re: Printing Bash and Kernel Version numbers using Perl

2011-03-12 Thread Alan Haggai Alavi

Hello Parag,


perl -MConfig -le 'print "$Config{perlpath}:$^V\n$ENV{SHELL}:
\n/kernel/$^O:"'


=pod code

perl -MConfig -e 'print "$Config{perlpath}:$^V\n$ENV{SHELL}:" . qx{ bash
--version | head -1 } . "/kernel/$^O:" . qx{ uname -r }'

=cut

Regards,
Alan Haggai Alavi.
--
The difference makes the difference

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




Re: help with array elements

2011-03-12 Thread Alan Haggai Alavi

Hello Ashwin,


I have an array which has few elements like
'1,2,3,4,2,3,1,2,1,1,1,4,6,7' i need to know how many times each
element has occurred in the same array. for example 1-5 times 2-3
times... could some one throw some light on how i can do this.


Store the array contents into a hash, updating the count each time:

=pod code

#!/usr/bin/env perl

use strict;
use warnings;

use Data::Dumper;

my @elements = ( 1, 2, 3, 4, 2, 3, 1, 2, 1, 1, 1, 4, 6, 7, );

my %count;
$count{$_}++ for @elements;

print Dumper \%count;

=cut

Regards,
Alan Haggai Alavi.
--
The difference makes the difference

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




Re: understanding the ||= operator

2011-02-12 Thread Alan Haggai Alavi
Hi,

> then that I don't understand is the program logic :-(

It is a logical OR. Quoting `perldoc perlop`:

   C-style Logical Or
   Binary "||" performs a short-circuit logical OR operation.  That
   is, if the left operand is true, the right operand is not even
   evaluated.  Scalar or list context propagates down to the right
   operand if it is evaluated.

$sheet->{'MaxRow'} = $sheet->{'MaxRow'} || $sheet->{'MinRow'};

Equivalent to:

unless ( $sheet->{'MaxRow'} ) {
$sheet->{'MaxRow'} = $sheet->{'MinRow'};
}

In English:
If $sheet->{'MaxRow'} has a value that evaluates to false, make
$sheet->{'MaxRow'} equal to $sheet->{'MinRow'}.

Though I have left the else clause,

By the way, it is not recommended to use `unless` for anything complex
as it can get in the way of ordinary thinking process. Use `if` and
`!`.

Regards,
Alan Haggai Alavi.
-- 
The difference makes the difference

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




Re: understanding the ||= operator

2011-02-12 Thread Alan Haggai Alavi
Hi,

> 12$sheet -> {MaxRow} ||= $sheet -> {MinRow};

Line 12 can be written as:
$sheet->{'MaxRow'} = $sheet->{'MaxRow'} || $sheet->{'MinRow'};

For example:
$variable_1 ||= $variable_2 is equivalent to $variable_1 = $variable_1
|| $variable_2.

The same applies to:

   **=+=*=&=<<=&&=
  -=/=|=>>=||=
  .=    %=    ^=   //=
x=

Regards,
Alan Haggai Alavi.
-- 
The difference makes the difference

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




Re: How to convert EURO Symbol € character to Hex

2011-01-19 Thread Alan Haggai Alavi
Hi Khabza,

> I have end up using ASCII Encoding instant of UTF-8
> it does not find any thing if I use 'BC' . chr(0x20AC) . '01'  then i
> change to 'BC' . chr(0x80) . '01'
>
> The following code works
>
> if ( $euros eq 'BC' . chr(0x80) . '01' ) {  # 0x20AC is the
> hexadecimal value of €
>         # ...
>     }

The Euro symbol is attributed 0x80 in Windows-1252 encoding and not in
ASCII. Euro symbol was created much later than the latest ASCII
revision.


> which I am not sure if my code will work to all version of windows.
> Is there a different between using ASCII or UTF-8?

UTF-8 encoding is a super-set of ASCII encoding.


Regards,
Alan Haggai Alavi.
-- 
The difference makes the difference

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




Re: How to convert EURO Symbol € character to Hex

2011-01-19 Thread Alan Haggai Alavi
Hi Khabza,

> now my problem is I cant type € symbol on my editor Textpad it return funny
> characters like €

Textpad probably allows you to set the encoding of the file to UTF-8,
I think. Set it to UTF-8 so that you will be able to type in the €
symbol.

use utf8;  # use whenever source code includes UTF-8

if ( $euros eq 'BC€01' ) {
# ...
}


__OR__

if ( $euros eq 'BC' . chr(0x20AC) . '01' ) {  # 0x20AC is the
hexadecimal value of €
    # ...
}

Regards,
Alan Haggai Alavi.
-- 
The difference makes the difference

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




Re: Function to print Object properties

2011-01-07 Thread Alan Haggai Alavi
Hi Parag,

On Friday 07 January 2011 07:55:38 Parag Kalra wrote:
> Anyways I want to know is there any function or a way that would
> reveal all the properties of the object.

Introspect the symbol table hash (stash):

use strict;
use warnings;

use Data::Dumper;
use Foo::Bar;

my $fob = Foo::Bar->new();
my $package = ref $fob;

{
no strict 'refs';
print Dumper \%{"${package}::"};
}

Regards,
Alan Haggai Alavi.
-- 
The difference makes the difference.

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




Re: need to get parent script name inside child script

2011-01-05 Thread Alan Haggai Alavi
Hi Sunita,

> How can I print parent test script name inside this postrun ?
`(caller)[1]` will return the the parent script's filename inside the
postrun script.

See `perldoc -f caller` for more information.

Regards,
Alan Haggai Alavi.
-- 
The difference makes the difference

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




Re: I can't understand this function that what are parameters ,can you help me?

2011-01-05 Thread Alan Haggai Alavi
Hi Yang,

> sub ok ($;$) {  } and sub is ($$;$) { }

Those are subroutines with prototypes. `sub NAME(PROTO)`

`sub ok ($;$)`
Requires one mandatory argument and an optional one. They are
separated by a semi-colon in the prototype definition. The arguments
will be considered in scalar context (due to the `$`).

`sub is ($$;$)`
Requires two mandatory arguments and an optional one. All of them will
be considered in scalar context.

See `perldoc perlsub` for more information.

Regards,
Alan Haggai Alavi.
-- 
The difference makes the difference

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




Re: 1st line of perl script

2011-01-04 Thread Alan Haggai Alavi
Hi Sunita,

>            Perl script  works without the first line ( perl Interpreter
> : #! /usr/bin/perl) . What is the real use of this line ? This line does
> not through any error on Windows where , this path does not exist .

It is a shebang line which is only useful in Unix-like operating
systems. In such systems, the shebang line should start in the first
column of the first line. When such a script with its executable bit
set is run by itself, the operating systems checks for the shebang
line to see which interpreter should be used for executing the script.

However, in Windows (and other non-Unix-like operating systems), the
shebang is usually considered a comment and skipped. Instead of the
shebang line, such systems depend on file extension associations or
explicit invocation of the script using the interpreter.

For more details, see: http://en.wikipedia.org/wiki/Shebang_(Unix)

Regards,
Alan Haggai Alavi.
-- 
The difference makes the difference

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




Re: Linux Uptime

2010-12-16 Thread Alan Haggai Alavi
Matt wrote:

> I have a perl script but I want to exit it if the uptime on the 
server
> is less then say an hour.  Any idea how I would get uptime with 
perl?


Hi,

You could use the distribution: Unix::Uptime 
(http://search.cpan.org/perldoc?Unix::Uptime)

Example:

use strict;
use warnings;

use Unix::Uptime;

my $uptime_hours = Unix::Uptime->uptime() / 3600;
if ( $uptime_hours < 1 ) {
exit(127);
}

Regards,
Alan Haggai Alavi.
-- 
The difference makes the difference.

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




Re: Directory Size

2010-10-28 Thread Alan Haggai Alavi
On Thursday 28 Oct 2010 06:30:01 Mike Blezien wrote:
> Hello,
> 
> I've been out of the programming game for a while and recently got back
> into some small programming projects. Just need to figure out if there is
> a Perl function to determine the total size of a folder and files? Meaning
> once we open/read a directory is to calculate the total, in MB's, the size
> of the files in a particular directory folder.
> 
> Thanks,
> 
> 
> Mike(mickalo)Blezien
> =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
> Thunder Rain Internet Publishing
> -=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-


Hi Mike,

You could make use of File::Find's find function along with stat.

=pod Example

use strict;
use warnings;

use File::Find;

my $size;
my $directory = '/path/to/some/directory';

sub determine_size {
if ( -f $File::Find::name ) {
$size += ( stat $File::Find::name )[7];
}
}

find( \&determine_size, $directory );

$size /= 1024 * 1024;

print "Total size: $size MB\n";

=cut

Relevant documents to read:
`perldoc File::Find` - http://perldoc.perl.org/File/Find.html
`perldoc -f stat` - http://perldoc.perl.org/functions/stat.html


Regards,
Alan Haggai Alavi.

--
The difference makes the difference.

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




Re: Perl Threads

2010-10-11 Thread Alan Haggai Alavi
On Sunday 10 Oct 2010 20:38:32 chillidba wrote:
> Can some body please point me to Perl Thread tutorials.(some pdf with
> examples)


Hi,

perldoc perlthrtut
http://perldoc.perl.org/perlthrtut.html

Regards,
Alan Haggai Alavi.
-- 
The difference makes the difference.

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




Re: Perl Threads

2010-10-11 Thread Alan Haggai Alavi
On Sunday 10 Oct 2010 20:38:32 chillidba wrote:
> Can some body please point me to Perl Thread tutorials.(some pdf with
> examples)


Hi,

perldoc perlthrtut
http://perldoc.perl.org/perlthrtut.html

Regards,
Alan Haggai Alavi.
-- 
The difference makes the difference.

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




Re: perl

2010-10-05 Thread Alan Haggai Alavi
On 4 October 2010 09:49, sheikh numan iqbal  wrote:
> i want to login and need help on perl...


Hi Numan,

Please let us know where you need help with. Consider expanding the question.

Regards,
Alan Haggai Alavi.
-- 
The difference makes the difference

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




Re: Callbacks

2010-09-09 Thread Alan Haggai Alavi
>   Hi
> 
> I am a newbie to Perl , I was reading through one of the beginner level
> books on perl. I did not understand the concept of "Callbacks" and i
> have the following questions on it:
> 
> 1. What are they ?
> 
> 2. Why do we need them ?
> 
> 3. What useful purpose do they achieve ?
> 
> I was reading the following code to understand it but could not comprehend.
> 
> *Code:*
> 
> #!/usr/bin/perl
> use warnings;
> use strict;
> use File::Find;
> find ( \&callback, "/");
> 
> sub callback {
> print $File::Find::name, "\n";
> }
> 
> *End Of Code:*
> 
> Thanks
> Jatin


Hi Jatin,

A callback is a reference to a subroutine. This reference when passed around, 
allows other code to invoke it.

File::Find's find() method accepts a subroutine reference as the first argument 
and a path in the filesystem as the second argument. find() traverses 
recursively in '/' and calls your code reference (callback()) for each 
file/directory it finds. Thus, your subroutine is able to get each item in the 
path as soon as they are encountered by File::Find's find(). If find() was not 
implemented to handle callbacks, the possible way to return encountered 
file/directory names will be as an array or hash of file/directory names after 
it has traversed and exhausted all possible file/directory names within the 
path.

Regards,
Alan Haggai Alavi.
-- 
The difference makes the difference.

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




Re: parsing csv

2010-07-02 Thread Alan Haggai Alavi
On 2 July 2010 15:56, Sharan Basappa  wrote:
> Hi Jason,
>
> Does CSV module come prebuilt so that I can avoid installing.
> I dont know SQL but my requirements are very modest.
> Extract lines and get filed and reformat them to another type.
>
> Regads,
> Sharan


Hi Sharan,

DBD::CSV is not in core. You can check it yourself by using the
`corelist` command-line frontend to Module::Corelist.

For example:
alanhag...@love:~$ corelist DBD::CSV

DBD::CSV was not in CORE (or so I think)

By the way, why do you resist installing modules from CPAN?

Regards,
Alan.
-- 
The difference makes the difference

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




Re: question abt array

2010-06-30 Thread Alan Haggai Alavi
On 30 June 2010 10:31, Chaitanya Yanamadala  wrote:
> Hai
>  i am in a situation like i have a scalar $value = 5
> now i need to create an array with the number i mean $value
> how can i do it??
>
> regards
> Chaitanya
>


Hi Chaitanya,

I am not sure if I understood your question well or not.

To create an array with the value, either push or unshift the value
into an existing array, or assign the value as an array item.

#!/usr/bin/env perl

use warnings;
use strict;

my $value = 5;
my @values;

# different cases:
# push @values, $value;
# unshift @values, $value;
# @values = ($value);

__END__

Please refer `perldoc -f push` and `perldoc -f unshift`.

Regards,
Alan Haggai Alavi.
-- 
The difference makes the difference

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




Re: about split and \d or . (.)

2010-04-11 Thread Alan Haggai Alavi
On 11 April 2010 21:10, Harry Putnam  wrote:
> Why is it that the first two splits do not produce any elements?
>
> #!/usr/local/bin/perl
>
> use strict;
> use warnings;
>
> my $var = 100421;
> my @elems1 = split(/\d/,$var);
> my @elems2 = split(/./,$var);
> my @elems3 = split(//,$var);
>
> if (@elems1){
>  print "elems1 has these elements:\n";
>  for(@elems1){
>    print "$_\n";
>  }
>  print"---       ---       ---=---       ---      ---\n";
> }
> if (@elems2){
>  print "elems2 has these elements:\n";
>  for(@elems2){
>    print "$_\n";
>  }
>  print"---       ---       ---=---       ---      ---\n";
> }
> if (@elems3){
>  print "elems3 has these elements\n";
>  for(@elems3){
>    print "$_\n";
>  }
>  print"---       ---       ---=---       ---      ---\n";
> }
>
>
>
>
>
> --
> To unsubscribe, e-mail: beginners-unsubscr...@perl.org
> For additional commands, e-mail: beginners-h...@perl.org
> http://learn.perl.org/
>
>
>

Hi Harry,


split considers the pattern given to it, as a delimiter within the
expression. Let us consider the three cases:

> my @elems1 = split(/\d/,$var);
Digits are the delimiters. Delimiters are stripped out of the string
by split. Hence, when digits are stripped out of a numeric expression,
the result will be undef.


> my @elems2 = split(/./,$var);
Again, anything is considered to be a delimiter due to the '.' (match
anything). Thus, again, the result is undef.


> my @elems3 = split(//,$var);
When the pattern is omitted, split splits on whitespace. Since the
string does not contain whitespaces, the string cannot be split and
split returns the string as it is.

Hope it is clear now.


Regards,
Alan Haggai Alavi.
-- 
The difference makes the difference

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




Re: Modules download from CPAN

2010-04-10 Thread Alan Haggai Alavi
Hi,

CPAN::Mini can be used to create/update local mirrors. minicpan script 
(http://search.cpan.org/perldoc?minicpan) which uses CPAN::Mini will be 
helpful in maintaining a local CPAN mirror.

Regards,
Alan Haggai Alavi.
-- 
The difference makes the difference.

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




Re: Decimal representation of binary file (unpack)

2010-04-08 Thread Alan Haggai Alavi
On 8 April 2010 11:00, Raymond Wan  wrote:
>
> Hi all,
>
> I would like to read in a binary file and extract the 4-byte ints from it.
>  Under Linux, something like "od -t uI".  I got it working as follows:
>
>
> my $buffer = ;
> my @buffer = split //, $buffer;
> for (my $i = 0; $i < length ($buffer); $i += 4) {
>  print unpack ('I', $buffer[$i].$buffer[$i + 1].$buffer[$i + 2].$buffer[$i +
> 3]), "\n";
> }
>
>
> And I was wondering if there was a way of doing this without the for loop.
>  (I am referring to the unpack; not the print.)  The perldocs for unpack
> says:
>
> "unpack does the reverse of pack: it takes a string and expands it out into
> a list of values. (In scalar context, it returns merely the first value
> produced.)"
>
> So, I thought this means I could give it a string and get a list of values
> like this:
>
> my @tmp = unpack ('I', $buffer);
>
> which does not work -- it only converts the first 4 bytes into an integer.
>  Anyway, if the above code with a for loop is the best way, I'm happy to
> stick with it -- just wondering if I'm missing out on something with
> unpack...
>
> Thanks!
>
> Ray

Hi Raymond,

Wildcards can be used within the template in pack. There is no need of
the inner loop you have written. For example, to unpack all signed
longs:

my @signed_longs = unpack ( 'I*', $buffer );

Regards,
Alan Haggai Alavi.
-- 
The difference makes the difference

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




Re: Need help to start with...

2010-04-04 Thread Alan Haggai Alavi
Hi Arjun,

>Can someone suggest me some good e-books or tutorials to start
>learning PERL?

Welcome to the Perl world. :-) By the way, the language is named Perl, and not 
PERL.

For online tutorials and links to books on the Perl language, you can check: 
http://perl-begin.org/

Regards,
Alan Haggai Alavi.
-- 
The difference makes the difference.

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




Re: error while installing win32::Registry module

2010-03-31 Thread Alan Haggai Alavi
Hi,

> Can't locate Win32/Registry.pm in @INC (@INC contains:
> C:/strawberry/perl/lib C:
> /strawberry/perl/site/lib C:\strawberry\perl\vendor\lib .) at GETIP.pl line
> 1.
> BEGIN failed--compilation aborted at GETIP.pl line 1.

It means that perl is unable to find the module Win32::Registry. So,
you need to either install it or add it to @INC for perl to find it.
>From checking CPAN, I read that Win32::Registry
(http://search.cpan.org/perldoc?Win32::Registry) is now obsolete use
Win32::TieRegistry (http://search.cpan.org/perldoc?Win32::TieRegistry)
instead.

Regards,
Alan Haggai Alavi.

--
The difference makes the difference

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




Re: Perl Beginners

2010-03-12 Thread Alan Haggai Alavi
Hi Sudheer,

Some links to help you get started:

http://perl-begin.org/
http://learn.perl.org/

Good luck learning Perl. :-)

Regards,
Alan Haggai Alavi.
-- 
The difference makes the difference.

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




Re: How to keep script alive if my shell closes

2010-02-13 Thread Alan Haggai Alavi
Hello Ariel,

You could use either GNU Screen (http://www.gnu.org/software/screen/)
or `nohup` command to run your script.

Regards,
Alan Haggai Alavi.
-- 
The difference makes the difference.

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




Re: Archive::Zip library on Solaris

2010-01-25 Thread Alan Haggai Alavi
>Hello all,
>
>I have a Perl Script that uses some of the Archive::Zip's methods for
>reading zip entries. Works fine on Linux, BUT on Solaris, this lib is not
>available in Solaris and I'm not allowed to install any lib in it. Is there
>a way to load the archive::zip lib dinamically, without installing it on the
>OS?
>
>Or, is there any default library on Solaris that I can read zip entries via
>filehandlers?
>
>Thanks!
>
>-- 
>Bruno Morelli Vargas
>Mail: brun...@gmail.com
>Msn: brun...@hotmail.com
>Icq: 165055101
>Skype: morellibmv

Hello Bruno,

Archive::Zip is a pure Perl module. You can download it from CPAN to some path 
where you have rw permissions and untar it. Then, modify @INC to use the 
library. No need to install it.

Regards,
Alan Haggai Alavi.
-- 
The difference makes the difference.

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




Re: Git Talk by Randal

2009-12-19 Thread Alan Haggai Alavi
>Who are you talking about? Is Merlyn some nickname I'm not aware of?
Hi,

Merlyn is Randal's nickname.

Regards,
Alan Haggai Alavi.
-- 
The difference makes the difference.

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




Re: Windoze Woez

2009-12-12 Thread Alan Haggai Alavi
Hi,

Windows requires you to use double quotes in place of single quotes. Saving to 
a file and executing it is the only way that is cross-platform, I suppose.

Regards,
Alan Haggai Alavi.
-- 
The difference makes the difference.

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




Re: passing command-line arg containing '@'

2009-12-10 Thread Alan Haggai Alavi
>I need to pass an command-line arg that is a string which contains the '@'.  
Is there any way to do this and also 'tell' Perl not to interpret this as 
other than a '@' character?
> 
>Thx.

Hi,

Perl would not do anything with command-line arguments unless you tell it 
otherwise. Check if you are using the EXPR form of eval to modify the argument 
list.

perl -MData::Dumper -le 'print Dumper \...@argv' @this @should @work

__Output__
$VAR1 = [
  '@this',
  '@should',
  '@work'
];

Regards,
Alan Haggai Alavi.
-- 
The difference makes the difference.

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




Re: About the perl index function question

2009-12-09 Thread Alan Haggai Alavi
Hi,

index $s, "e", 3;

This means "position of the first 'e' on or after position 3". The position of 
the 'e' is counted from the start of the string. Counting starts from 0.

Regards,
Alan Haggai Alavi.
-- 
The difference makes the difference.

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




Re: Feedback, please

2009-12-09 Thread Alan Haggai Alavi
>Hello,
>
>I would like to have someone looking over my script, which is a basic
>frontend for playing radio with mplayer. In particular, I'm wondering how I
>could get rid of all those elsif's when parsing the arguments; as you can
>see, there's lots of them, and I suspect that there's a better way of doing
>things.
>
>Any criticism on anything is highly appreciated, since I want to learn.
>Cheers.

Hi,

Looks like you forgot to provide a link to the script.

If you do not want to use lots of elsifs, try using switch statements 
introduced by perl 5.10.

http://perldoc.perl.org/perlsyn.html#Switch-statements

Regards,
Alan Haggai Alavi.
-- 
The difference makes the difference.

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




Re: Can I design a website using Perl

2009-12-06 Thread Alan Haggai Alavi
Hi,

There are many ways by which a website/application can be built using Perl. 
Mainly:

* CGI
* mod_perl
* Any web framework

All of the above have modules in CPAN. For simple tasks and for websites with 
not much traffic, you can go the CGI way. For much more complex tasks, you have 
the choice to choose between mod_perl or a web framework such as Catalyst.

The Catalyst Web Framework (http://www.catalystframework.org/) helps in 
getting an application up and running in a few moments. It also has several 
modules backing it.

The disadvantage of using Perl for web development is that it is a bit hard to 
deploy. However, the advantages outweigh the disadvantage by a considerable 
margin.

Regards,
Alan Haggai Alavi.


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




Re: Regex to get last 3 digits of a number.

2009-11-24 Thread Alan Haggai Alavi
Hi,

The following should work:

my $number = '0111';
my ($index) = ( $number =~ /\d+(\d{3})/ );

$index would contain the last three digits: '111'.

To learn about regular expressions in Perl, you can go through `perldoc 
perlre` and `perldoc perlretut`. The Perldoc website 
(http://perldoc.perl.org/) can be of help as well.

Regards,
Alan Haggai Alavi.

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




Re: Extract url and text from a website

2008-09-16 Thread Alan Haggai Alavi

Hi,

Do not use regular expressions to parse HTML. Regexps will break at some  
point. Use HTML::Parser.


Regards,
Alan Haggai Alavi.
--
The difference makes the difference.

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