how to write a sub in Perl


 
Thread Tools Search this Thread
Top Forums Programming how to write a sub in Perl
# 1  
Old 05-18-2010
how to write a sub in Perl

hi, i am a really new to Perl. i have a following code that is working well.

"

i know this is really simple, but i cant figure out a way to do this. can someone help me please?Smilie

Last edited by usustarr; 05-28-2010 at 07:17 PM..
# 2  
Old 05-18-2010
Quote:
Originally Posted by usustarr
Code:
#!/usr/bin/perl


sub copy
{
# <-- in theory it should work if you replace this comment with the two lines from below
my($bit,$file,$data) = @_;

 $string =`cat test.txt | grep  archive`;
 open  IO,">> $file" or die "Cannot open $file for output: $!\n";
 print IO  ref $data eq 'ARRAY' ? @$data : ref $data eq "SCALAR"? $$data : ' ';
 close IO;

}



     $name = "jen";
     $filename = join "", "../History/", $name, "test.log";
     copy('write',$filename,\ $string);


i would like to move following lines into the sub,
$name = "jen";
$filename = join "", "../History/", $name, "test.log"

i know this is really simple, but i cant figure out a way to do this. can someone help me please?Smilie
This User Gave Thanks to pseudocoder For This Post:
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Read/write perl file

Hi I am trying to build a web form where it can take the input from the user and write it to a file. And when I will open that form again that for should read the file that was created at the 1st step and all the fields should auto populate from that file. I have 20 text fields in my form. I... (1 Reply)
Discussion started by: sauravrout
1 Replies

2. Shell Programming and Scripting

[Perl] Write to a file

Hai #!user/bin/perl -------- -------- print("$line.......\n"); ------- ------ I want to write inside $line into a file like run.log How i can pleasw tel me Thanks kiran (4 Replies)
Discussion started by: kiran425
4 Replies

3. Shell Programming and Scripting

Perl write and read on same file

Hi, I am trying to do a write operation followed by a read operation on the same file through Perl, expecting the output produced by read to contain the new lines added, as follows: #! /usr/bin/perl -w open FH, "+< testfile" or die "$@"; print FH "New content added\n"; while (my $line =... (1 Reply)
Discussion started by: royalibrahim
1 Replies

4. Shell Programming and Scripting

Perl script to create/write into spreadsheet

Hi, I need help in debug following script. can somebody help....!!! #!/usr/bin/perl -w use strict; use Spreadsheet::WriteExcel; # Create a new workbook called simple.xls and add a worksheet. my $workbook = Spreadsheet::WriteExcel->new('simple.xls'); my $worksheet =... (1 Reply)
Discussion started by: chettyravi
1 Replies

5. Shell Programming and Scripting

Need a perl script to read and write the data

Hi, I have on Designdocument in that information is stored with in tabular format.I need Perlscript to read and write the datausing perl script? Regards, Ravi (0 Replies)
Discussion started by: toravi.pentaho
0 Replies

6. Programming

How to write a new line to the end of the file in Perl?

i am very new to Perl. i am using Ubuntu. i have a string call $string that contains following words "new line". i also have a data file as follows. djfibjbet etitrbjijbtr rrge rgjierjegjeri jerijg kijij jijij i want to write my new line to my data file as follows. djfibjbet... (3 Replies)
Discussion started by: usustarr
3 Replies

7. Shell Programming and Scripting

PERL write to file help

Very new to perl and have an exististing script which I need to capture some variables to a log file. My below code works well, except the @cmds array has some %20 which I need replaced with a space and some <br> which needs a \n instead. I tried messing around with a foreach, but have failed. ... (6 Replies)
Discussion started by: numele
6 Replies

8. Shell Programming and Scripting

perl -write values in a file to @array in perl

Hi can anyone suggest me how to write a file containing values,... say 19 20 21 22 .. 40 to an array @array = (19, 20, ... 40) -- Thanks (27 Replies)
Discussion started by: meghana
27 Replies

9. Shell Programming and Scripting

Need help to write a Perl script

Hello friends, I am having a awk script which does my goal , but I want to learn perl , after learning the basics in perl now I am trying to convert my nawk script to perl . Please help me to do some task in perl that I ve already did in nawk. Like I am facing some problem in... (10 Replies)
Discussion started by: user_prady
10 Replies

10. Shell Programming and Scripting

need help to write perl code

I have 2 files , one is master file and another file i am genearting which contains Number of fails for all host & version. The first file is master file which contains 2 column, Test Case name and Product Name: daily/DB/attach/attach_redundancy.exp: YRS daily/DB/help/help.exp: ... (0 Replies)
Discussion started by: getdpg
0 Replies
Login or Register to Ask a Question