Hi,
I am new to perl programming.
I have a requirement to validate the input received from the user with the file and send it to the printer.
For Eg:
script -o option -p printername -f filename
script - is the name of my script
-o option- is the option that has to be validated with another file
-p printername - is the name of my printer
-f filename - is the filename which has to be printed.
how to use this split function in this case. I want to take" -o option" and compare it with the file.
I already have a print queue ready. what is teh command to send the filename to the printer.
Please help me.
Thanks.
13 1970
To process command line options, you can make use of GetOpt::Std module that comes with default Perl installation.
i had used the below command to check whether the file exists or not.
eventhough the file exists in proper path, it is going to else part.
or if the path is wrong, it is not dying....
Please help... -
#!/usr/bin/perl
-
-
use strict;
-
-
my $file = <STDIN>;
-
print ( $file );
-
$ENV{'PPD'} = $file;
-
-
# file
-
-
open (FILE, $file) || die "cannot open";
-
-
if (-e $file) {
-
print "exists \n";
-
}
-
else
-
{
-
print ( $file );
-
print "not \n";
-
}
-
close(FILE);
-
i had used the below command to check whether the file exists or not.
eventhough the file exists in proper path, it is going to else part.
or if the path is wrong, it is not dying....
Please help... -
#!/usr/bin/perl
-
-
use strict;
-
-
my $file = <STDIN>;
-
print ( $file );
-
$ENV{'PPD'} = $file;
-
-
# file
-
-
open (FILE, $file) || die "cannot open";
-
-
if (-e $file) {
-
print "exists \n";
-
}
-
else
-
{
-
print ( $file );
-
print "not \n";
-
}
-
close(FILE);
Do remember to chop the newline while taking input from command line/terminal. That will solve the issue. -
chomp(my $file = <STDIN>);
-
Hi,
Thanks for the reply..
i have got the option from the user Eg: -o xxx=yyy
@options=@ARGV[0..$#ARGV];
I want to ignore -o and take only xxx in one variable and yyy in another variable..
Please help me with the commands..
Thank You.
If you are calling the script like,
perl script.pl -o xxx=yyy
use: -
use strict;
-
my $option=$ARGV[1]; # get second argument
-
my ($first, $second) = split /=/,$option; # split across '='
-
print "$first\n$second\n";
-
However, if you are handling multiple options, it is better to use Getopt::Std as I said before.
- Nithin
Hi Nithin,
Thank you for the reply.
this is what i exactly wanted.
perl script.pl -o xxx=yyy -o aaa=bbb -o asd=asd ........
i want to execute my script in this way...
so using getopt, returns only the last value.
and also i want to ignore -o and use only xxx=yyy, aaa=bbb, asd=asd values.
xxx,aaa,asd separately in a array and yyy,bbb,asd separately in a array......
please help me if you have any idea on this.
Thanks in advance...
Hi Nithin,
Thank you for the reply.
this is what i exactly wanted.
perl script.pl -o xxx=yyy -o aaa=bbb -o asd=asd ........
i want to execute my script in this way...
so using getopt, returns only the last value.
and also i want to ignore -o and use only xxx=yyy, aaa=bbb, asd=asd values.
xxx,aaa,asd separately in a array and yyy,bbb,asd separately in a array......
please help me if you have any idea on this.
Thanks in advance...
Try: -
use strict;
-
-
my @options=grep(!/-o/,@ARGV); # get all args other than -o
-
my (@first,@second);
-
foreach(@options) {
-
my ($first, $second) = split /=/;
-
push @first,$first;
-
push @second,$second;
-
}
-
Thanks for this valuable information.
If there is any rating for the replies I would like to give you 10.
Thanks a lot.
I am executing the below script in the terminal.
/usr/lib/filter/rip "<some options>" /anyfilename > /outputfile
I am executing a script named rip with some options and giving the input file and redirecting it to a file.
I want to use perl script to execute this command.
I used system command as below.
system("/usr/lib/filter/rip "<some options>" /anyfilename > /outputfile");
It is not working. How to execute.
Please help.
I have executed the below command and it is partially working.
@pr = ("/usr/lib/rip","option","/test",">","/del");
print ( "@pr" );
system("@pr");
Bash#:/usr/lib/rip option /test > /del
This <option> has to be displayed in double quotes ("option").
But this double quotes are taken as space.
The command I want to execute is as below.
Bash#:/usr/lib/rip "option" /test > /del
Please help.
I have executed the below command and it is partially working.
@pr = ("/usr/lib/rip","option","/test",">","/del");
print ( "@pr" );
system("@pr");
Bash#:/usr/lib/rip option /test > /del
This <option> has to be displayed in double quotes ("option").
But this double quotes are taken as space.
The command I want to execute is as below.
Bash#:/usr/lib/rip "option" /test > /del
Please help.
The double quotes around options should be escaped. For ex., consider the command you need is -
#path/rip "Hello man" input.txt > output.txt
-
Then, the system command should be as below: -
system("path/rip \"Hello man\" input.txt > output.txt");
-
Thanks for the reply.
I want to store the output file. If i store it in an $var or @array, the file is not saved properly.
my script:
my $file = "/tmp/input";
my @pr = "/tmp/file.log";
@command = ("/usr/lib/rip \"options\" $file > @pr");
system ( "@command" );
file.log shows some file size. When i try to open it, it is not responding.
please let me know how to solve this issue.
This issue is not present wen a txt file is given as input. other than text file all other files are giving problem.
Thanks,
KevinADC 4,059
Recognized Expert Specialist - my $file = '/tmp/input';
-
my $out = '/tmp/file.log';
-
-
my $command = ("/usr/lib/rip \"options\" $file > $out");
-
system ($command);
Sign in to post your reply or Sign up for a free account.
Similar topics
by: Arjen |
last post by:
Hi All,
What I want to is using a string as PATTERN in a split function. This makes
it possible for me to change the PATTERN on one place in my script...
For example:
$separator = ";";
$line...
|
by: SL_McManus |
last post by:
Hi All;
I am fairly new to Perl. I have a file with close to 3000 lines
that I would like to split out in a certain way. I would like to put
the record type starting in column 1 for 2 spaces,...
|
by: Henry Chen |
last post by:
Hi,
I have a string that needs to be parsed into the string. The separator is
not char. It is something like " at ". With current string.Split function,
it doesn't work. Is there any exist...
|
by: Vamsi |
last post by:
Hi,
I am trying a basic opearation of splitting a multiline value to an
array of single lines(Actually making Address into AddressLine1,
AddressLine2).
I used Environment.NewLine in split, I...
|
by: mb |
last post by:
I was wondering if there is an easy, more useful Split function that will
split with a string delimiter like "<>" or "////"?
|
by: Itzik |
last post by:
can i split this string
string str = "aa a - bb-b - ccc"
with this delimiter
string del = " - "
i want recieve 3 items : "aa a" , "bb-b" , "ccc"
|
by: Ben |
last post by:
Hi
I am creating a dynamic function to return a two dimensional array from a
delimeted string.
The delimited string is like:
field1...field2...field3...
field1...field2...field3......
|
by: sck10 |
last post by:
Hello,
I have a list of email addresses that I need to send email to from the
website. I am trying to use the "Split" function to get all the To's and
then use the uBound function for the...
|
by: Jordi Rico |
last post by:
Hi,
I know I can split a string into an array doing this:
Dim s As String()=Regex.Split("One-Two-Three","-")
So I would have:
s(0)="One"
s(1)="Two"
|
by: John |
last post by:
Hi
I have written a Split function which in turn calls the standard string
split function. Code is below;
Function Split1(ByVal Expression As String, Optional ByVal Delimiter As
String = " ",...
|
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...
|
by: marktang |
last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
|
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...
|
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...
|
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: isladogs |
last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM).
In this session, we are pleased to welcome a new...
|
by: conductexam |
last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
|
by: TSSRALBI |
last post by:
Hello
I'm a network technician in training and I need your help.
I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs.
The...
|
by: 6302768590 |
last post by:
Hai team
i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...
| |