Sponsored Content
Top Forums Shell Programming and Scripting Passing arguments to Perl Function Post 302287930 by pludi on Monday 16th of February 2009 03:50:18 AM
Old 02-16-2009
Try it like this (changes in red)
Code:
#!/usr/local/bin/perl
use strict;
use warnings

my $DATABASE = "/home/myfile/DATABASE_DIR";

open_my_doc( "Pricelist" );

sub open_my_doc {
print "$DATABASE/$_[0]\n"; 
open(my FH, "< $DATABASE/$_[0]" ) or die $!;
        while (<FH>) {
          print $_;
        }
        close FH;
}

use strict and use warnings help catch a lot of programmatic errors that otherwise would only show themselfs later (maybe even only as heisenbugs).
Calling perl -c <script> does a syntax check without running it, so that syntactic error (like your last }) can be found.
I suggest installing perltidy, as it will clean your code in terms of indentation and unneeded clutter (like ; at the end of blocks when they aren't needed)
 

10 More Discussions You Might Find Interesting

1. UNIX for Dummies Questions & Answers

passing arguments

I'm trying to pass a filename, or all the files in the current directory to the ls command with a script. Unsuccessful so far, here are a few of my attempts: #!/bin/ksh read fname #if (( $# > 0 )); then $fname | ls -l #fi this produces a long listing of all the files in my current... (4 Replies)
Discussion started by: jpprial
4 Replies

2. Shell Programming and Scripting

Passing arguments to a Perl script

I am playing around with Perl and wrote the script below that is executed from the command line, it will split data up in a file based on a value supplied. When executed you provide two arguments - the file that contains the data to be split and the character you want to split by. It works as... (4 Replies)
Discussion started by: jyoung
4 Replies

3. Shell Programming and Scripting

Passing global variable to a function which is called by another function

Hi , I have three funcions f1, f2 and f3 . f1 calls f2 and f2 calls f3 . I have a global variable "period" which i want to pass to f3 . Can i pass the variable directly in the definition of f3 ? Pls help . sars (4 Replies)
Discussion started by: sars
4 Replies

4. Shell Programming and Scripting

Perl Function Array Arguement Passing

Hi All, I have some questions regarding array arguements passing for Perl Function. If @array contains 2 items , arguements passing would be like Code_A. But what if @array needs to add in more items, the rest of the code like $_ will have to be modified as well (highlighted in red), which is... (5 Replies)
Discussion started by: Raynon
5 Replies

5. Shell Programming and Scripting

passing arguments

Hi I have a script to which I pass multiple arguments, for example lets say the script name is "abc". I run the script like ./abc def /file <directory location> In the above "def" is the first argument and "/file" is the second argument. I expect <directory location> that is passed after... (4 Replies)
Discussion started by: zmfcat1
4 Replies

6. UNIX for Dummies Questions & Answers

Passing arguments

I need to pass arguments to a shell script.My batch is calling some java program. ################# x=$1 y=$2 java -classpath program ################### if first parameter and second parameter is null then java -classpath program if first parameter is not null and second parameter is... (3 Replies)
Discussion started by: mnjx
3 Replies

7. Shell Programming and Scripting

Reading a string and passing passing arguments to a while loop

I have an for loop that reads the following file cat param.cfg val1:env1:opt1 val2:env2:opt2 val3:env3:opt3 val4:env4:opt4 . . The for loop extracts the each line of the file so that at any one point, the value of i is val1:env1:opt1 etc... I would like to extract each... (19 Replies)
Discussion started by: goddevil
19 Replies

8. Shell Programming and Scripting

Problem in passing date to external function from perl script.

my $sysdate = strftime('%Y-%m-%d', localtime ); biDeriveByDate('Table_Str',$sysdate,\@lIndx,\@lResVals) In a perl script, when I'm trying to pass $sysdate to some external function it's not working since $sysdate is passed as a string mentioned above but my function is expecting a date value... (1 Reply)
Discussion started by: Devesh5683
1 Replies

9. Shell Programming and Scripting

Passing arguments to a perl script

Hi I need to pass comma seperated arguments to a perl script? It is like: Exect.pl -d GUI1,GUI2,GUI3 and I need to store these argsGUI1,GUI2,GUI3 in an array. can anyone suggest how to do that: (1 Reply)
Discussion started by: rkrish
1 Replies

10. Shell Programming and Scripting

Problems passing shell arguments to perl

Semi-newbie, so flame throwers to 'singe-only', please. ;-) I have a large number of (say) .html files, where I'd like to do a recursive in-place search and replace a particular string. The following bit of perl works fine: perl -pi -e 's/oldstring/newstring/g' `find ./ -name *.html` ... (2 Replies)
Discussion started by: johnny_canucl
2 Replies
Text::Sass::Functions(3pm)				User Contributed Perl Documentation				Text::Sass::Functions(3pm)

NAME
Text::Sass::Functions VERSION
$LastChangedRevision: 59 $ SYNOPSIS
DESCRIPTION
SUBROUTINES
/METHODS new Creates a new object. rgb(red, green, blue) Converts triplet into a color. red(color) Returns the red part of a color. green(color) Returns the green part of a color. blue(color) Returns the blue part og a color. mix(color1, color2, weight = 50%) Mixes two colors together. hsl(hue, saturation, lightness) Converts as hsl triplet into a color. hue(color) Returns the hue part of a color. saturation(color) Returns the saturation part of a color. lightness(color) Returns the lightness part of a color. adjust_hue(color) Changes the hue of a color, can be called as adjust-hue. lighten(color, amount) Makes a color lighter. darken(color, amount) Makes a color darker. saturate(color, amount) Makes a color more saturated. desaturate(color, amount) Makes a color less saturated. grayscale(color) Converts a color to grayscale. complement(color) Returns the complement of a color. unquote(str) Removes the quotes from a string. quote(str) Adds quotes to a string. percentage(num) Converts a unitless number to a percentage. round(num) Rounds a number to the nearest whole number. ceil(num) Rounds a number up to the nearest whole number. floor(num) Rounds a number down to the nearest whole number. abs(num) Returns the absolute value of a number. unit(num) Returns the unit of a value. unitless(num) Returns true if the number has no unit. DIAGNOSTICS
CONFIGURATION AND ENVIRONMENT
DEPENDENCIES
strict warnings Carp POSIX Readonly Convert::Color Text::Sass::Expr INCOMPATIBILITIES
BUGS AND LIMITATIONS
Missing alpha routines rgba & hsla methods. mix() doesn't support weight. AUTHOR
Author: BjA~Xrn-Olav Strand LICENSE AND COPYRIGHT
This library is free software; you can redistribute it and/or modify it under the same terms as Perl itself, either Perl version 5.8.10 or, at your option, any later version of Perl 5 you may have available. perl v5.14.2 2012-04-05 Text::Sass::Functions(3pm)
All times are GMT -4. The time now is 08:14 AM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy