Re: Converting to capital only one word in a line

2007-01-15 Thread Leonid Grinberg

The backslash escapes the character following it.


Oh, that's right. Sorry.


Using scalar() there is redundant as the expression is already in scalar
context.  Also using scalar(@split_home) - 1 will not work correctly if the
value of $[ has been changed.


What exactly *is* $[? It has been confusing me for some time.

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




Re: Converting to capital only one word in a line

2007-01-14 Thread Leonid Grinberg

my @split_line = split(/\:/, $line);
my $home = $split_line[5];
my @split_home = split(/\/, $home);
return uc($split_home[scalar(@split_home) - 1]);

On 1/11/07, Emilio Casbas [EMAIL PROTECTED] wrote:

I know that this is not a exact perl question, but maybe someone has a
perl solution.

You have the passwd file such this:


test:x:593:501::/usr/local/etc5/test:/bin/bash


and you have to convert it to:


test:x:593:501::/usr/local/etc5/TEST:/bin/bash


Only converting to capital letter the last part of the home directory.
Anyone have some way to achieve it?

Regards.
Emilio C.

--




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





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




Re: Converting to capital only one word in a line

2007-01-14 Thread Leonid Grinberg

You don't have to escape the colon in a regular expression.


Oh, cool. Didn't know that.


 my $home = $split_line[5];
 my @split_home = split(/\/, $home);
 ^^^
Syntax error.  The terminating delimiter is missing.


I am confused. What do you mean, the terminating delimter is missing?
It seems alright to me...


scalar(@split_home) - 1 could also be written as $#split_home or just -1.


I did not know that ``-1'' would work. However, I prefer scalar() to $#.

There is More than One Way to Do It! :-)

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




Re: Negate a regular expression

2006-12-30 Thread Leonid Grinberg

!~ will return true if the thing on the right does not match.
In your case, however, using unless seems more logical. Something like

exit unless (lc($answer) =~ /^[y|yes]$/)

should work. The ^ and $ are there to make sure that the string
contains nothing but ``y'' or ``yes''. Make sure that you do
chomp($answer) before running this, though, because the newline
character may break it.

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




Re: Strings vs Arrays

2006-12-30 Thread Leonid Grinberg

To push something to an array:

push(@array, $data);

To push something onto a scalar:

$scalar = $scalar . $data;
-or-
$scalar .= $data;

The better method depends entirely on what you intend to do with the
data and how you have it. It is also very easy to both split a string
into an array,

@array = split(/pattern_to_split_over/, $string); # note that the
pattern can just be //, to split every character into its own element
of the array

and to make an array into a string:

foreach (@array) { $string .= $_; }

One thing to note, though, is that array operations in Perl (push(),
splice(), etc.) are wicked fast.

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




Modifying a PNG File

2006-12-02 Thread Leonid Grinberg

Hello,

Is there a (relatively simple) way to modify an image in Perl?
Ideally, this would be a PNG or GIF image. I just need to be able to
modify the colors of specific pixels.

Thanks in advance!

--
Leonid Grinberg
[EMAIL PROTECTED]

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




Passing a hash to a function

2006-07-18 Thread Leonid Grinberg

Hello all,

I have a question about passing a hash to a fucntion. Suppose you had
the following script:


sub function
{
 my %operating_systems = populate_hash(%operating_systems);
 do_something_with_hash();
}

sub populate_hash
{
 my %operating_systems = ?;
 $operating_systems{microsoft} = Windows;
 $operating_systems{apple} = Macintosh;
 ...
 return %operating_systems;
}


What should the ? be? If it was an array, it would be @_; if it
was a scalar, it would be
my ($scalar) = @_, $_[0], or shift; How about with a hash?

Thank you in advance!

--
Leonid Grinberg
[EMAIL PROTECTED]
http://www.lgrinberg.org

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




Re: Perl OS system equivalence or Perl scripts for UNIX-and-Windows

2006-05-26 Thread Leonid Grinberg

Yes, as people have mentioned your options are:

-Run the scripts with Cygwin, which will ensure that most system
commands will be set up for you (if this is for general distribution,
you can make it a system requirement, although that's a pretty heave
system requirement to have).
-Rewrite the UNIX commands yourself (or use those that others created
already). Many of them are fairly easy to recreate, but some are more
difficult. Obviously, rewriting Vi in Perl is stupid, but you can
quite easily do things like ls, rm, etc.

--
Leonid Grinberg
[EMAIL PROTECTED]
http://www.lgrinberg.org

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




Re: What are the most successful applications of Perl? Thanks.

2006-05-23 Thread Leonid Grinberg

SLASHDOT!!! Amazing that this has not yet been mentioned!

--
Leonid Grinberg
[EMAIL PROTECTED]
http://www.lgrinberg.org

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




Re: Hi

2006-05-15 Thread Leonid Grinberg

I am a novice to perl,I would like to learn perl in a systematic way,
Whats the best way to start with,I dont have any experience of
programming Language, But I came to know that perl is a Good
Programming Language


Whether or not you do choose to use a book or not, remember: always
try doing some excersizes. You *cannot* just read, you have to try it
firsthand. This is as simple as writing your first program that just
prints out ``Hello World'' to testing out the ugliest regular
expressions (you will eventually learn what these are). Remember, you
are just learning, and so you are free to experiment.

Good Luck!

--
Leonid Grinberg
[EMAIL PROTECTED]
http://www.lgrinberg.org

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




Re: General Perl/Web questions

2006-04-28 Thread Leonid Grinberg

Yeah, what that would pretty much mean is that you will make a file
called, say, CommonFuncts.pm and then in each Perl script say

use CommonFuncts;

Alternatively, you can make a common_functs.pl file, where each one of
the above actions is performed in a subroutine (the file should only
have subroutines, and should not do anything outside of them (except
like use strict;)) and then, from within each file, you could do
something like

BEGIN
{
   do ('common_functs.pl');
   die if $@;
}


The BEGIN just makes the block be loaded at the beginning of
execution, the do() function loads files and eval()s them (except
since all we have are subroutines, nothing is actually performed, you
just now have all of the new subroutines to work with) and the 'die if
$@' exits if there were syntax errors in the common_functs.pl file and
it prints them.

Either of the two ways work, I just prefer do();

Cheers!

--
Leonid Grinberg
[EMAIL PROTECTED]
http://www.lgrinberg.org

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