473,395 Members | 1,969 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,395 software developers and data experts.

Need help new to perl code!!!!

6
I am new to perl. I am having trouble with this code line I wrote. On the third line I keep getting this message when I go to run this. This is just the first part of the code. Please any advice would help.I am using TextPad, and window xp pro os.

Usage:C:\Perl\ch1\ filename at C:\Perl\ch1\ line 4, <> line 1.
Press any key to continue . . .

[my $in = $ARGV[0];
unless (defined $in) {
die "Usage: $0 filename";]
Nov 27 '06 #1
8 1817
GunnarH
83
Expand|Select|Wrap|Line Numbers
  1. C:\home>type test.pl
  2. my $in = $ARGV[0];
  3. unless (defined $in) {
  4.         die "Usage: $0 filename";
  5. }
  6. print "File: $in\n";
  7.  
  8. C:\home>perl test.pl myfile.txt
  9. File: myfile.txt
  10.  
  11. C:\home>
Nov 27 '06 #2
gooop
6
[quote=gooop]I am new to perl. I am having trouble with this code line I wrote. On thef fourth line I keep getting this message when I go to run this. . Please any advice would help.I am using TextPad, and window xp pro os.This program is suppose to make a modified copy of a text file. In the copy ,every string Fred should be replaced with Larry. I want to have the input filename at the command line. But everytime I go to run this I get the error message below on the 4th line of my code. What is wrong with Usage , am I missing a syntax or something.

Usage:C:\Perl\ch1\ filename at C:\Perl\ch1\ line 4, <> line 1.
Press any key to continue . . .

[#!usr/bin/perl -p
my $in = $ARGV[0];
unless (defined $in) {
die "Usage: $0 filename";
}
print "File: $in\n";
my $out = $in;
$out =~ s/(\.\w+)?$/.out/;
unless (open IN, "<$in") {
die "Can't open '$in': $!";
}
unless (open OUT, ">$out") {
die "Can't write '$out': $!";
}
while (<IN>) {
s/Fred/Larry/gi;
print OUT $_;
}]
Nov 28 '06 #3
miller
1,089 Expert 1GB
Did you try what GunnarH suggested?
Nov 28 '06 #4
gooop
6
Did you try what GunnarH suggested?
Yes I did try this but I still get the error message about line 4. What is wrong with Usage: The only reason I re-posted it was so that I included my entire code because what he wrote on the line after line 4 was the same as mine. The second posting was also more clear on what I am trying to do, that is why I posted it twice.I am very new to programming and I very new to forums.
Nov 29 '06 #5
gooop
6
Yes I did try this but I still get the error message about line 4. What is wrong with Usage: The only reason I re-posted it was so that I included my entire code because what he wrote on the line after line 4 was the same as mine. The second posting was also more clear on what I am trying to do, that is why I posted it twice.I am very new to programming and I very new to forums.

I used the use diagnostics; in my code and it it says uncaught exception by the user, same line 4.
Nov 29 '06 #6
GunnarH
83
Did you try what GunnarH suggested?
Yes I did try this but I still get the error message about line 4.
When doing so, did you start the command with perl?
Nov 29 '06 #7
gooop
6
Yes , beleive so i used
Expand|Select|Wrap|Line Numbers
  1.  #!/user /bin/perl -p 
As the first line of my code
Dec 3 '06 #8
GunnarH
83
When doing so, did you start the command with perl?
Yes , beleive so i used
Expand|Select|Wrap|Line Numbers
  1.  #!/user /bin/perl -p 
As the first line of my code
I wasn't talking about the shebang line, I was talking about the command, i.e. what you are typing on the command line when invoking the script.
Expand|Select|Wrap|Line Numbers
  1. perl test.pl myfile.txt
  2. ^^^^
Did you start that typing with the word "perl"?

As regards the shebang line, I'd recommend that you drop it. Besides the switches, it's redundant on Windows, and I'm not sure what that -p switch does.
Dec 4 '06 #9

Sign in to post your reply or Sign up for a free account.

Similar topics

4
by: eight02645999 | last post by:
hi i need help with converting a piece of perl code to python ...... my $start = '\'; my $file = '\'; my $end = '\'; ..... while(<FILE>) #open a file {
1
by: Riyadh Hossain | last post by:
I am developing USPS shipping API for my site. All the work is going on testing phase. My site uses PHP/MySQL. Now I am working on USPS tracking/confirm. I can send request and get responses from...
1
by: eadavid | last post by:
HI, I am a beginner to perl and I need to write perl code for checking a good die in the wafermap. Here is the wafermap look like in file ....XXXX111111111X1111XXXX.......
7
by: group8perl | last post by:
I have this perl code written using Notepad which works fine using Apache but when i try to run the perl script on a Linix browser i get a program/script failure error. Can someone please help me...
3
by: behrooz | last post by:
Hi Dear friends I need a code in perl to receive a list reference and a hash reference copy the contents of the array into the hash such that the even elements of the array are the keys of the...
2
by: sainiamit25 | last post by:
Hi All, I have writte a perl code. The perl code simple do some calculation and based on that, it takes a specific action for a device. But i do not have any logging mechanism for this. By this i...
1
by: sandy2481 | last post by:
Hi Friends, I'm a beginner in perl. Can anyone please provide me with a perl code to read a HTML file and write into excel file. Regards, Sandy
3
by: andrewkl | last post by:
hi, I have the following Perl code that inserts a string to an Oracle DB via a stored procedure: #!/usr/local/bin/perl ## Perl v5.8.6 built for sun4-solaris use strict; BEGIN...
1
by: RaviRajhulk | last post by:
I need to execute the perl code after a delay of say an minute.. and i need to write to do this in the perl code itself....Plz help
1
by: rajpar | last post by:
Environment: Solaris (client + server) db2 version 7.2 latest fixpak (DB2 v7.1.0.111", "s050516" and "U803330") Compiler: gcc Here is my SP code executed on the client: CREATE PROCEDURE...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.