Beefy Boxes and Bandwidth Generously Provided by pair Networks
laziness, impatience, and hubris
 
PerlMonks  

Re: why my system call won't work?

by SciDude (Friar)
on Jun 12, 2004 at 18:07 UTC ( #363637=note: print w/ replies, xml ) Need Help??


in reply to why my system call won't work?

I recently needed to store some SKU information in a subdirectory. This is the simple example I arrived at. More experienced Monks are welcome to tear this apart with improvement suggestions:

#!/usr/bin/perl -w use strict; use Storable; use Data::Dumper; use Cwd; # Note it is possible to override chdir to update $ENV{PWD} +but I could not get it to work under strict my $dir; my $cwd = cwd; my %skuname = ( Lots of stuff here ) # Hard coded data to store in sub +directory # Where are we in working directory now? print "Current Directory by cwd is $cwd \n"; print "Current Directory by env is ", $ENV{'PWD'} , "\n"; # Lets take that info and create a new current working directory print "Appending skudbcurrent to dir\n"; $dir = $cwd . "/skudbcurrent"; print "We wish to move to $dir "; # This directory may or may not exist print "Checking to see if skudbcurrent exists, if not then create +it\n"; unless (-d $dir) { mkdir $dir; print "We had to make $dir \n"; }; # We created it if it was not already there so now move into it # Note that cwd chdir and $ENV{'PWD'} get out of sync although the mov +e was successful chdir $dir; #move into the new directory print "Moved to new directory:",$ENV{'PWD'} , "\n"; print "Which should match $dir\n"; # We made the move. Now store some data in the new location. store(\%skuname, 'skudb') or die "Can't store %a in new location!\ +n"; # Success! Now print out what we think was stored print "Done!\n"; print "Saved the file! er following:\n"; print Dumper( \%skuname );

I hope this brief example is useful for you.


SciDude
The first dog barks... all other dogs bark at the first dog.


Comment on Re: why my system call won't work?
Download Code
Re^2: why my system call won't work?
by Zaxo (Archbishop) on Jun 12, 2004 at 20:10 UTC

    Cwd::chdir() works fine with strict. Did you import chdir? Even if you didn't, I don't see how that would annoy stricture.

    $ cd $ perl -Mstrict -Mwarnings -MCwd=chdir -e'chdir "src"; print $ENV{"PWD +"}, $/' /home/zaxo/src $

    After Compline,
    Zaxo

      hrmmm....so for what I want: i should do chdir "error/srd"; then chdir; ?

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://363637]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others taking refuge in the Monastery: (7)
As of 2015-07-04 09:50 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    The top three priorities of my open tasks are (in descending order of likelihood to be worked on) ...









    Results (59 votes), past polls