LinuxQuestions.org
Share your knowledge at the LQ Wiki.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 01-08-2010, 05:08 PM   #16
bartonski
Member
 
Registered: Jul 2006
Location: Louisville, KY
Distribution: Fedora 12, Slackware, Debian, Ubuntu Karmic, FreeBSD 7.1
Posts: 443
Blog Entries: 1

Rep: Reputation: 48

Quote:
Originally Posted by rweaver View Post
Another thing I'd point out is... you should really be specifying the commandline uses in the script itself--

Code:
use strict;
use warnings;
There is really no time you don't want those on.
Hallelujah, Brother.

I didn't really learn that this was the right way to do things until I started working in a mixed Unix/Windows environment:

I used to run perl scripts using this shebang line.

Code:
#! /usr/bin/perl -w
That won't work under Windows.

(What's worse is when someone opens one of your perl files in a windows text editor... then saves it without makeing any changes... except for the nice little ^M characters littered throughout the code. This will mess up the shebang line because /usr/bin/perl is not the same as /usr/bin/perl^M... meaning that the shebang line won't work under Unix, either).
 
Old 01-11-2010, 02:53 AM   #17
ashok.g
Member
 
Registered: Dec 2009
Location: Hyderabad,India
Distribution: RHEl AS 4
Posts: 215

Original Poster
Rep: Reputation: 32
Quote:
Originally Posted by bartonski View Post
Code:
> cat /tmp/asdf.pl
#!usr/bin/perl
use strict;
use warnings;
open F, "/proc/$$/cmdline";
my @a=split "\000", <F>;
print @a,"\n";
close F;

> perl -w /tmp/asdf.pl asdf asdf sadf sadf
perl-w/tmp/asdf.plasdfasdfsadfsadf
Please observe that I used print @a,"\n"; instead of print @a,"\n";.
Why this is happening?
 
Old 01-11-2010, 04:51 AM   #18
Sergei Steshenko
Senior Member
 
Registered: May 2005
Posts: 4,481

Rep: Reputation: 454Reputation: 454Reputation: 454Reputation: 454Reputation: 454
Quote:
Originally Posted by ashok.g View Post
Please observe that I used print @a,"\n"; instead of print @a,"\n";.
Why this is happening?
What "this" ?
 
Old 01-11-2010, 06:51 AM   #19
Telemachos
Member
 
Registered: May 2007
Distribution: Debian
Posts: 754

Rep: Reputation: 60
Quote:
Originally Posted by ashok.g View Post
Please observe that I used print @a,"\n"; instead of print @a,"\n";.
Why this is happening?
I believe you mean print @a, "\n"; instead of print "@a\n";.

If you interpolate an array in double quotes and print it, you get each item separated by a space. If, however, you print the array unquoted, you get all the items concatenated together without any separation of any kind.

Code:
#!/usr/bin/env perl
use strict;
use warnings;

my @stuff = qw/foo bar bizz buzz fizzbuzz/;

print "With quotes:\n";
print "\t@stuff\n";

print "Without quotes:\n";
print "\t", @stuff, "\n";
Output:
Code:
telemachus ~ $ perl array_print
With quotes:
	foo bar bizz buzz fizzbuzz
Without quotes:
	foobarbizzbuzzfizzbuzz
Note that the behavior of interpolated arrays (space separated) can be adjusted by tinkering with the $" built-in variable.

Last edited by Telemachos; 01-11-2010 at 06:58 AM.
 
Old 01-11-2010, 07:01 AM   #20
Sergei Steshenko
Senior Member
 
Registered: May 2005
Posts: 4,481

Rep: Reputation: 454Reputation: 454Reputation: 454Reputation: 454Reputation: 454
Quote:
Originally Posted by Telemachos View Post
I believe you mean print @a, "\n"; instead of print "@a\n";.

If you interpolate an array in double quotes and print it, you get each item separated by a space. If, however, you print the array unquoted, you get all the items concatenated together without any separation of any kind.

Code:
#!/usr/bin/env perl
use strict;
use warnings;

my @stuff = qw/foo bar bizz buzz fizzbuzz/;

print "With quotes:\n";
print "\t@stuff\n";

print "Without quotes:\n";
print "\t", @stuff, "\n";
Output:
Code:
telemachus ~ $ perl array_print
With quotes:
	foo bar bizz buzz fizzbuzz
Without quotes:
	foobarbizzbuzzfizzbuzz
Note that the behavior of interpolated arrays (space separated) can be adjusted by tinkering with the $" built-in variable.
Such answers leave the OP no chance to learn to ask questions correctly in the first place.
 
Old 01-11-2010, 04:11 PM   #21
Telemachos
Member
 
Registered: May 2007
Distribution: Debian
Posts: 754

Rep: Reputation: 60
Quote:
Originally Posted by Sergei Steshenko View Post
Such answers leave the OP no chance to learn to ask questions correctly in the first place.
That is your opinion, and you have every right to it. In my opinion, your style of answer ("Here are the docs. Read them. If you don't understand something, write here, explaining the first word you don't understand and why...") makes people ask elsewhere (or give up).

I will continue to answer in my style. You can continue to disagree with my choices. Such is life.
 
Old 01-12-2010, 01:00 AM   #22
Sergei Steshenko
Senior Member
 
Registered: May 2005
Posts: 4,481

Rep: Reputation: 454Reputation: 454Reputation: 454Reputation: 454Reputation: 454
Quote:
Originally Posted by Telemachos View Post
That is your opinion, and you have every right to it. In my opinion, your style of answer ("Here are the docs. Read them. If you don't understand something, write here, explaining the first word you don't understand and why...") makes people ask elsewhere (or give up).

I will continue to answer in my style. You can continue to disagree with my choices. Such is life.
They'd better give up - otherwise their job has to be done by others.

As someone else wrote in this forum - instead of learning nowadays "Internet forum learning" or something like this has become immensely popular. I.e. instead of making an effort to read and understand people just ask questions in forums without making an effort first.

Unfortunately, I too often had to work with people who never bothered to read the documentation on tools they were systematically/repeatedly using.

It was a disaster, i.e. they didn't understand how the tools were working/what they were doing, they just new command line format for certain tasks they were routinely performing. They couldn't make even a minimal modification of the command lines when needed (i.e. all they could was, say, replacing file names on command lines), they couldn't analyze and correct mistakes they made (and we all make mistakes) - exactly because they didn't understand what they and the tools were doing.

Kind of "command line monkeys" if you wish - similar to "coding monkeys".

As you said, such is life. I.e. the more you do the job of others, the more the others take it for granted.
 
0 members found this post helpful.
Old 01-12-2010, 08:33 AM   #23
Telemachos
Member
 
Registered: May 2007
Distribution: Debian
Posts: 754

Rep: Reputation: 60
Quote:
Originally Posted by Sergei Steshenko View Post
They'd better give up - otherwise their job has to be done by others.

<snip>

As you said, such is life. I.e. the more you do the job of others, the more the others take it for granted.
This is a reasonable response, so I will try to explain why I disagree. I agree that if people use forums only to get the answer, they won't ever learn.

However, my hope is that if I give more explanation and people read what I write and think about it, they will learn. I also generally post links to fuller documentation or articles or mention books. If someone posts question after question about very basic things and doesn't show any increase in knowledge, I stop posting answers. But I don't mind writing fuller answers at first.

Perl's documentation is excellent, but it can be overwhelming for someone new to the language or new to programming. I remember how it felt for me at first. Everything was in there, but (1) I couldn't always find things and (2) sometimes the explanations went way over my head.

Anyhow, that's why I often write fuller answers.
 
  


Reply

Tags
arguments, perl



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
call perl script through another perl script with arguments nanda22 Linux - Newbie 21 07-21-2009 12:18 AM
Problem with passing arguments in Perl bahadur Programming 1 05-30-2005 01:47 AM
perl arguments zaken Programming 1 02-27-2005 11:19 AM
command arguments in perl djgerbavore Programming 1 12-30-2004 08:06 AM
Perl: Getting a script to accept arguments JStew Programming 10 03-10-2003 06:56 AM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 07:38 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration