LinuxQuestions.org
Review your favorite Linux distribution.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Software
User Name
Password
Linux - Software This forum is for Software issues.
Having a problem installing a new program? Want to know which application is best for the job? Post your question in this forum.

Notices


Reply
  Search this Thread
Old 08-16-2020, 02:22 PM   #1
Fred27377
Member
 
Registered: Jun 2020
Posts: 68

Rep: Reputation: Disabled
simple perl script that does not print


I have this script below.It runs and when you execute $? it returns from BASH no errors but it will not print. This sounds limited but i have seen similiar errors before and maybe if you can clear one you can start to clear them all. Just thinking. Thanks for looking and considering.

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

my $list = 0;
my $i = 1;
my $a = 0;
if (my $i < 10){


print my $i;
fi

}
 
Old 08-16-2020, 02:45 PM   #2
tofino_surfer
Member
 
Registered: Aug 2007
Posts: 483

Rep: Reputation: 153Reputation: 153
You are overusing the keyword my. This should only be used when first declaring a variable. Also there is no fi in perl.

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

my $list = 0;
my $i = 1;
my $a = 0;

if ($i < 10){

     print $i;

}
Every time you entered "my $i" you were declaring a new variable $i.
 
3 members found this post helpful.
Old 08-16-2020, 07:38 PM   #3
TB0ne
LQ Guru
 
Registered: Jul 2003
Location: Birmingham, Alabama
Distribution: SuSE, RedHat, Slack,CentOS
Posts: 26,684

Rep: Reputation: 7971Reputation: 7971Reputation: 7971Reputation: 7971Reputation: 7971Reputation: 7971Reputation: 7971Reputation: 7971Reputation: 7971Reputation: 7971Reputation: 7971
Quote:
Originally Posted by Fred27377 View Post
I have this script below.It runs and when you execute $? it returns from BASH no errors but it will not print. This sounds limited but i have seen similiar errors before and maybe if you can clear one you can start to clear them all. Just thinking. Thanks for looking and considering.
Code:
#!/usr/bin/perl -d
#use warnings;
#use strict;

my $list = 0;
my $i = 1;
my $a = 0;
if (my $i < 10){

print my $i;
fi
}
Didn't you say you wrote a perl script in another thread??
https://www.linuxquestions.org/quest...ml#post6156074

Yet you can't do a simple counter in THIS thread??? Again, as with your other threads, there is AMPLE documentation and sample scripts for you to look at. Have you actually looked at any of them??
 
1 members found this post helpful.
Old 08-17-2020, 05:46 AM   #4
pan64
LQ Addict
 
Registered: Mar 2012
Location: Hungary
Distribution: debian/ubuntu/suse ...
Posts: 21,930

Rep: Reputation: 7321Reputation: 7321Reputation: 7321Reputation: 7321Reputation: 7321Reputation: 7321Reputation: 7321Reputation: 7321Reputation: 7321Reputation: 7321Reputation: 7321
you must not comment out those
Code:
use warnings;
use strict;
lines and you will see your code is incorrect.
(commenting out these lines will not solve anything, just suppress the error messages).
also you can try this: http://perlcritic.com/critique/file
 
2 members found this post helpful.
  


Reply



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
[SOLVED] Trying to print list in terminal,print the results,not print from. ewpoppy Linux - Newbie 4 04-24-2020 07:33 AM
perl - get print to print *now* in cgi script (hard to explain). Linicks Programming 6 12-24-2015 08:14 AM
Print output of a script to screen using Perl/Multiple installation of Perl Modules metallica1973 Linux - General 1 02-17-2011 05:59 PM
Print-to-file print driver to print PDF Bill Fox Linux - General 3 05-02-2006 04:15 PM
perl(Cwd) perl(File::Basename) perl(File::Copy) perl(strict)....What are those? Baldorg Linux - Software 1 11-09-2003 08:09 PM

LinuxQuestions.org > Forums > Linux Forums > Linux - Software

All times are GMT -5. The time now is 11:01 AM.

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