hosted by liquidweb


Go Back   Web Hosting Talk : Web Hosting Main Forums : Programming Discussion : perl scripting
Reply

Forum Jump

perl scripting

Reply Post New Thread In Programming Discussion Subscription
 
Send news tip View All Posts Thread Tools Search this Thread Display Modes
  #1  
Old 06-26-2005, 07:11 PM
always always is offline
Newbie
 
Join Date: Jun 2005
Posts: 6

perl scripting


I am trying to get the file using command-line argument such as "$>datafile -s filename "but unfortunately it is not working. The errors i am getting as below and only print out the first word for each line in the data file. Anyone know this easy stuff please help me to correct the code that i code wrong. I am trying to do command line checking on is "-s" specified, and the filename specified. If "-s" was specified, then set a true/false variable. If a filename was specified,then connect file to STDIN. Here is my code and errors. Please help! I searched on the net but no luck to get what i am want. Therefore, I need you guys expert help.

Thank you and cheer!

Best
Always


#textfile is data file

!/usr/bin/perl -w
$textfile = <~/bin/textfile>

$simple=0;

if ($ARGV[0] eq "-s")
{
$simple=1;
}

if ($simple)
{
do something with the record.\n";
}

if ($ARGV[0])
{
open (STDIN, "<$textfile") || die "Cannot open file $textphone,\n$!";
print "Opened file $textfile ok.\n";
}

while ($data =<STDIN>)
{
chomp $data;

print "$data";
}

TESTING USING THIS COMMAND textphone -s testing
/users/bin/textfile: line 1: What: command not found
/users/bin/textfile: line 2: The: command not found
/users/bin/textfile: line 4: you: command not found
/users/bin/textfile: line 5: or: command not found
/users/bin/textfile: line 6: people: command not found
/users/bin/textfile: line 7: syntax error near unexpected token `678-1255.'
/users/bin/textfile: line 7: `(575)456-3425. (459)-788-1054 as a phone number,'

IF I USE THIS COMMAND ./testing OR testing
Unquoted string "record" may clash with future reserved word at /users/bin/testing line 19.
Unquoted string "n" may clash with future reserved word at /users/bin/testing line 19.
String found where operator expected at /users/bin/testing line 24, near "open (STDIN, ""
(Might be a runaway multi-line "" string starting on line 19)
(Missing semicolon on previous line?)
String found where operator expected at /users/bin/testing line 24, near "$textfile") || die ""
(Missing operator before ") || die "?)
Bareword found where operator expected at /users/bin/testing line 24, near "") || die "Cannot"
(Missing operator before Cannot?)
String found where operator expected at /users/bin/testing line 25, near "print ""
(Might be a runaway multi-line "" string starting on line 24)
(Missing semicolon on previous line?)
Bareword found where operator expected at /users/bin/testing line 25, near "print "Opened"
(Do you need to predeclare print?)
Bareword found where operator expected at /users/bin/testing line 25, near "$textfile ok"
(Missing operator before ok?)
Unquoted string "ok" may clash with future reserved word at /users/bin/testing line 25.
Unquoted string "n" may clash with future reserved word at /users/bin/testing line 25.
String found where operator expected at /users/bin/testing line 32, near "print ""
(Might be a runaway multi-line "" string starting on line 25)
(Missing semicolon on previous line?)
Scalar found where operator expected at /users/bin/testing line 32, near "print "$data"
(Do you need to predeclare print?)
String found where operator expected at /users/bin/testing line 32, at end of line
(Missing semicolon on previous line?)
syntax error at /users/bin/testing line 19, near "do something with the "
Can't find string terminator '"' anywhere before EOF at /users/bin/testing line 32.


Last edited by always; 06-26-2005 at 07:17 PM.


Sponsored Links
  #2  
Old 06-26-2005, 09:26 PM
deadserious deadserious is offline
Aspiring Evangelist
 
Join Date: May 2002
Posts: 441
Re: perl scripting

Quote:
Originally posted by always

!/usr/bin/perl -w
You might try changing that to #!/usr/bin/perl -w

Quote:
Originally posted by always

$textfile = <~/bin/textfile>
Is this supposed to be the path to a file named textfile? Either way you're missing a semi-colon there. It might work better like:

$textfile = '/path/to/textfile';

If you're running the script from the command line you might want to try:

perl -c yourscriptname

That will let you know if there's any syntax errors.

  #3  
Old 06-27-2005, 08:17 AM
always always is offline
Newbie
 
Join Date: Jun 2005
Posts: 6
Re: Re: perl scripting

Thank you for your respone. The thing that you pointed out were not the issue, just the body code itself have problem and I don't know how to make it works. The -s is make-up it could be -a, -whatever, it just for ourself convinence when testing.


Quote:
Originally posted by deadserious

You might try changing that to #!/usr/bin/perl -w


Is this supposed to be the path to a file named textfile? Either way you're missing a semi-colon there. It might work better like:

$textfile = '/path/to/textfile';

If you're running the script from the command line you might want to try:

perl -c yourscriptname

That will let you know if there's any syntax errors.

Sponsored Links
  #4  
Old 06-27-2005, 09:42 AM
Slidey Slidey is offline
Web Hosting Master
 
Join Date: Apr 2003
Location: UK
Posts: 2,560
Code:
#!/usr/bin/perl -w

use strict;

my $textfile = "/tmp/textfile"

my $simple=0;

if ($ARGV[0] eq "-s")
{
  $simple=1;
}

if ($simple)
{
  print "do something with the record.\n";
}

if ($ARGV[0])
{
  open FILE, "$textfile" || die "Cannot open file $textphone,\n$!";
  print "Opened file $textfile ok.\n";
}

while (my $data = <FILE>)
{
  chomp $data;

  print "$data";
}

  #5  
Old 06-27-2005, 11:24 AM
always always is offline
Newbie
 
Join Date: Jun 2005
Posts: 6
THE ERROR I AM GETTING FOR THIS IS "Use of uninitialized value in string eq at /users/bin/testing1

if ($ARGV[0] eq "-s")
{
$simple=1;
}


Quote:
Originally posted by Slidey
Code:
#!/usr/bin/perl -w

use strict;

my $textfile = "/tmp/textfile"

my $simple=0;

if ($ARGV[0] eq "-s")
{
  $simple=1;
}

if ($simple)
{
  print "do something with the record.\n";
}

if ($ARGV[0])
{
  open FILE, "$textfile" || die "Cannot open file $textphone,\n$!";
  print "Opened file $textfile ok.\n";
}

while (my $data = <FILE>)
{
  chomp $data;

  print "$data";
}

  #6  
Old 06-27-2005, 11:35 AM
Slidey Slidey is offline
Web Hosting Master
 
Join Date: Apr 2003
Location: UK
Posts: 2,560
you should do a check to see if $ARGV[0] exists first

something like:

if($ARGV[0] && ($ARGV[0] eq "-s")) {



your problem existed because if there is no argv[0] it had nothing to compare to "-s" but had to do your comparison

  #7  
Old 06-27-2005, 11:50 AM
fastduke fastduke is offline
WHT Addict
 
Join Date: Dec 2003
Location: Earth
Posts: 144
Code:
#!/usr/bin/perl -w
#
use warnings;
use strict;


use Getopt::Std;


getopt('s');

our($opt_s);

if ($opt_s){
    open FILE, "$opt_s" || die "Cannot open file $opt_s,\n$!";
    print "Opened file $opt_s ok.\n";

    while (<FILE>){
        chomp;
        print "$_\n";
    }
}
else{
    print "No options given\n";
    print "Usage: ./script.pl -s <filename>\n";
}

__________________
if($php !== $javascript){
echo "Good it's not supposed to be";
}

  #8  
Old 06-27-2005, 11:52 AM
Slidey Slidey is offline
Web Hosting Master
 
Join Date: Apr 2003
Location: UK
Posts: 2,560
i wondered if someone'd go that route..

  #9  
Old 06-27-2005, 12:00 PM
fastduke fastduke is offline
WHT Addict
 
Join Date: Dec 2003
Location: Earth
Posts: 144
Hehe.

Quote:
Originally posted by Slidey
i wondered if someone'd go that route..

__________________
if($php !== $javascript){
echo "Good it's not supposed to be";
}

Reply

Related posts from TheWhir.com
Title Type Date Posted
Linux Malware Operation Windigo Infects 25,000 Web Servers Web Hosting News 2014-03-19 11:44:53
Admin-Ahead Server Technologies Listing 2014-04-16 23:31:34
cPanel & WHM Software 11.36 Reaches Stable Tier Status Web Hosting News 2013-04-09 11:44:33
FireHost Report Shows Cross-Site Scripting Attacks Up 160 Percent from Q3 Web Hosting News 2013-01-30 14:43:57
cPanel Security Updates Address Perl Module Vulnerabilities Web Hosting News 2012-12-06 12:55:54


Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes
Postbit Selector

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

Forum Jump
Login:
Log in with your username and password
Username:
Password:



Forgot Password?
Advertisement:
Web Hosting News:



 

X

Welcome to WebHostingTalk.com

Create your username to jump into the discussion!

WebHostingTalk.com is the largest, most influentual web hosting community on the Internet. Join us by filling in the form below.


(4 digit year)

Already a member?