Perl: How to avoid warnings for superfluous values returned?


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Perl: How to avoid warnings for superfluous values returned?
# 1  
Old 07-23-2013
Perl: How to avoid warnings for superfluous values returned?

Hi all,

a question for the Perl knowledgeable:

I have use warnings; enabled.
I use something like:
Code:
($sec,$min,$hour,$mday,$mon,$year,$wday,$yday,$isdst) = localtime(time);

In the further code I only work with some of the returned variables, as the others I have no need for.
Though the turned on warnings complain about this single usage:
Code:
Name "main::wday" used only once: possible typo at ./somescript.pl line 39.

I do not want to turn off warnings, neither do I have any usage for those variables/values. If I imagine I had use strict; turned on, I would even get a compilation error...

I had read many answers about people having this problem, but the most common answer was, that you "have to" use the variables.
I mean, I do not know how to be more explicit with localtime() to avoid returned values I do not need, besides writing it to an array and just use the elements I need, which in my eyes would be a stupid workaround (if it works) and not better than the way the warnings complain about.

Enlighten me please and thanks in forward Smilie

Update:
I use now @thetime = localtime(time) and it stopped complaining, when I address the elements I need. Still there is memory used up for the returned values of the function.
The code is worse readable than the 1st example where each variable is assigned.
I do not understand why people explain on their websites, it is a kind of bad habit... Looks more like the limited capability of the warnings to distinguish between a somewhere in the code forgotten variable and a returned value of a function that simply gives back a bunch of values.

Last edited by zaxxon; 07-23-2013 at 09:58 AM..
# 2  
Old 07-23-2013
You could put that piece of code inside its own block with no warnings enabled.

Code:
use warnings;
...
...
{
  no warnings;
  ($sec,$min,$hour,$mday,$mon,$year,$wday,$yday,$isdst) = localtime(time);
}
...
...

Alternatively, use the "our" keyword.

Code:
use warnings;
...
...
our ($sec,$min,$hour,$mday,$mon,$year,$wday,$yday,$isdst) = localtime(time);
...
...

This User Gave Thanks to durden_tyler 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

Perl :: reading values from Data Dumper reference in Perl

Hi all, I have written a perl code and stored the data into Data structure using Data::Dumper module. But not sure how to retreive the data from the Data::Dumper. Eg. Based on the key value( Here CRYPTO-6-IKMP_MODE_FAILURE I should be able to access the internal hash elements(keys) ... (1 Reply)
Discussion started by: scriptscript
1 Replies

2. UNIX for Dummies Questions & Answers

How to compare to values returned from sql in shell scripting?

hey i am using this code to connect to sql , store the value in variable and then compare it with another variable after some time by executing the same query but the desired result is not coming #!/bin/bash val=$(sqlplus -s rte/rted2@rel76d2 <<ENDOFSQL set heading off set feedback off... (11 Replies)
Discussion started by: ramsavi
11 Replies

3. Shell Programming and Scripting

How to avoid Delimiter occuring in column values in .csv file

Hello Gurus, I need to create a file from a .csv file extracting specific columns only. File structure is Column1,Column2,Column3,Column4 abcd,1234,"asdf, tew,123",123456 efgh,234,asdf,654321 My output file should have abcd,123456 efgh,654321 Can you pls help me with the code. ... (10 Replies)
Discussion started by: ritesh.bhawsar
10 Replies

4. Shell Programming and Scripting

Capture query returned values in file.

Hi All, I am connecting to Oracle DB from UNIX script. Want to capture all dates between start date and end date and store them in file. Once this is done, want to read dates one by one. How to achive this in UNIX and Oracle? Please let me know if you have any idea on the same. Thanks and... (4 Replies)
Discussion started by: Nagaraja Akkiva
4 Replies

5. Shell Programming and Scripting

Adding values returned through foreach

Hi Folks I wanted to do something like this : Go through all the top_level_dirs inside a particular dir. Grep a particular string in the files in each of those dirs. Count the occurence of that string in that file Keep adding these (wc) values so that I can know the total occurences of that... (1 Reply)
Discussion started by: abcdino
1 Replies

6. Shell Programming and Scripting

Perl, searching multiple files and printing returned line to new file

I am trying to find a way to utilise the full potential of my cpu cores and memory on my windows machine. Now, I am quite familiar with grep, however, running a Unix based OS is not an option right now. Unfortunately, the 32 bit grep for windows that I am running, I cannot run multiple... (1 Reply)
Discussion started by: Moloch
1 Replies

7. Shell Programming and Scripting

Perl Array Variables to be returned to main

Hi All, I can;t seem to print out the array in sequence using the below subroutine. My first element in the array @lotsuffix is suppose to be $lotsuffix as defined in the subroutine, but when the array variable is being pass on the main program, my first element actually becomes $lotsuffix ! ... (4 Replies)
Discussion started by: Raynon
4 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. UNIX for Dummies Questions & Answers

is /. superfluous? why not just say / ?

is /. superfluous? why not just say / ? I can see a use for . on its own. But /. seems superfluous/redundant. I'm guessing it must have some good reason, there's a whole website named after it!! (5 Replies)
Discussion started by: james hanley
5 Replies

10. Shell Programming and Scripting

typeset and values returned from awk output

Somebody can please give a highlight on this. The problem shows only on Linux(Redhat) not any other unix flavors :confused: Linux : $unset m $m=`find . -newer rman_padev_20051206195000.out -name "*L0.rman" -exec ls -l {} \; | awk '{ s+=$5 } END{printf("%.0f", s)}'` $echo $m 7425089536... (0 Replies)
Discussion started by: prathom
0 Replies
Login or Register to Ask a Question