473,395 Members | 1,608 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.

help for function

NSC
Hi all,

I have this :

<SNIP>
foreach $item (@NEW_FILES)
print "\n $item \n ";

($size,$atime,$mtime,$ctime) = (stat($item))[7..10];
$a_time = localtime($atime);
$m_time = localtime($mtime);
$c_time = localtime($ctime);

printf ("\n Size(bytes): %10d \n" ,
$size );
print " Creation Time : $c_time \n" ;
print " Last Modification : $m_time \n" ;
print " Last Access : $a_time \n";
print " Last Access : $a_time \n";
}
<SNIP>

and I like to do this:

<SNIP>
foreach $item (@NEW_FILES)

stats;
}
<SNIP>

so I made:

<SNIP>
sub stats
print "\n $item \n ";
($size,$atime,$mtime,$ctime) = (stat($item))[7..10];
$a_time = localtime($atime);
$m_time = localtime($mtime);
$c_time = localtime($ctime);

print "\n Size: $size \n";
print " Creation Time : $c_time \n" ;
print " Last Modification : $m_time \n" ;
print " Last Access : $a_time \n";
}
<SNIP>

and it didn't work !

I made the same with hash functions and it works.

I declared all variables with 'my' , is that the problem.

thanks all.

Simon S.


Jul 19 '05 #1
4 2547
"NSC" <ne**********@bluewin.ch> wrote in message news:<40**********@news.bluewin.ch>...
I have this :
[ snip not real Perl code that doesn't use my() ]
and it didn't work !
Never say "didn't work". Always say what happened and how this
differed from what you wanted.
I declared all variables with 'my' , is that the problem.


Not in the code you showed us you didn't. Anyhow without a clue what
you actually did all I can asy that declaring variables is more often
part of the solution than part of the problem.

Please produce a minimal but complete script that demonstrates what
you are trying to do.

See posting guidelines in comp.lang.perl.misc for this and much other
good advice.

This newsgroup does not exist (see FAQ). Please do not start threads
here.
Jul 19 '05 #2
NSC wrote:
<SNIP>
foreach $item (@NEW_FILES)
stats;
}
<SNIP>


There's your problem. You should have used
stats($item);
and changed the first executable line of stats() to be
my $item = shift;
Jul 19 '05 #3
NSC
Thank you Joe.

It works great, but (IF you have time) I have a subsidiary question :

why does this one work ?
I don't see the difference !

<SNIP>
sub hash {

open(FILE, $item_full_name);
binmode(FILE);
bla, bla
}

bla, bla

foreach (@FILES) {

$item_full_name = $folder . "\\" . $_;
$filecount++;
hash;
}
<SNIP>

Have a nice day.

Simon S.
"Joe Smith" <Jo*******@inwap.com> a écrit dans le message news:
SHCFc.3059$JR4.3003@attbi_s54...
NSC wrote:
<SNIP>
foreach $item (@NEW_FILES)
stats;
}
<SNIP>


There's your problem. You should have used
stats($item);
and changed the first executable line of stats() to be
my $item = shift;

Jul 19 '05 #4
NSC wrote:
It works great, but (IF you have time) I have a subsidiary question :
why does this one work ?


If you're using variables declared with 'my' (and you should), then
you have to explicitly pass the variable to the subroutine.

In general it is bad to use subroutines that rely on constantly changing
global variables (like your $item_full_name). Pass the changeable bits
as subroutine arguments.
-Joe
Jul 19 '05 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

7
by: Alan Bashy | last post by:
Please, guys, In need help with this. It is due in the next week. Please, help me to implement the functions in this programm especially the first three constructor. I need them guys. Please, help...
2
by: Jackson Yap | last post by:
can someone kind enough to help me look at the attached html and js file? Why is it that the javascript menu could not work at www.apchosting.net but could work at...
5
by: Craig Keightley | last post by:
Please help, i have attached my page which worksin IE but i cannnot get the drop down menu to fucntion in firefox. Any one have any ideas why? Many Thanks Craig ...
6
by: James Radke | last post by:
Hello, I have a multithreaded windows NT service application (vb.net 2003) that I am working on (my first one), which reads a message queue and creates multiple threads to perform the processing...
1
by: Michael D. Reed | last post by:
I am using the help class to display a simple help file. I generated the help file using Word and saving it as a single page Web page (.mht extension). I show the help file with the following...
1
by: Rahul | last post by:
Hi Everybody I have some problem in my script. please help me. This is script file. I have one *.inq file. I want run this script in XML files. But this script errors shows . If u want i am...
0
by: gunimpi | last post by:
http://www.vbforums.com/showthread.php?p=2745431#post2745431 ******************************************************** VB6 OR VBA & Webbrowser DOM Tiny $50 Mini Project Programmer help wanted...
4
by: Stef Mientki | last post by:
I'm making special versions of existing functions, and now I want the help-text of the newly created function to exists of 1. an extra line from my new function 2. all the help text from the old...
22
by: Amali | last post by:
I'm newdie in c programming. this is my first project in programming. I have to write a program for a airline reservation. this is what i have done yet. but when it runs it shows the number of...
1
by: Bob | last post by:
Hi, Hope you can help me with this one. I'm at my wits end. I'm trying to create an intelligent edit-box like the excellent "Customer" one at the URL: ...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
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...
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
marktang
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,...
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
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
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.