Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl: the Markov chain saw
 
PerlMonks  

Re: I can crash perl

by Jenda (Abbot)
on Mar 30, 2015 at 13:02 UTC ( [id://1121823]=note: print w/replies, xml ) Need Help??


in reply to I can crash perl

my @tmp_1; my @tmp_2; my @tmp_3; my @tmp_4; my @tmp_5; my @tmp_6;

Are you kidding me?!? If someone under my command turned in this kind of code, he'd get it thrown on his head and would not leave the office until he gets it rewritten.

Jenda
Enoch was right!
Enjoy the last years of Rome.

Replies are listed 'Best First'.
Re^2: I can crash perl
by frozenwithjoy (Priest) on Mar 30, 2015 at 20:03 UTC

    Furthermore, I just noticed that @tmp_7 is used in the code further down, but not declared with the others. I think I speak for everyone when I say I want to know why @tmp_7 is so special. Enquiring minds want to know. I want to know!

Re^2: I can crash perl
by mark4 (Acolyte) on Apr 07, 2015 at 08:55 UTC
    I'm a hardware engineer. I never learneded about programing. :) so be nice. :) And yes, I know learnded is not a word

      Please read Program Repair Shop and Red Flags, especially the Use compound data structures part.

      A group of (numbered) variables is always the wrong solution. You should use an array of arrays or array of hashes instead.

      Instead of the several arrays, you should have one array of hashes and instead of

      for($i = 0; $i <= $last_dir; $i++) { ( $deleted_file[$i] , $void , $the_dir[$i] , $first_pointer[$i] , $last_pointer[$i] , $has_subdir[$i] , $has_iden[$i] ) = split (/\"\|/, $tmp_2[$i], 7); #printf ("sort_dirs_debug2: %5d fp: %5d, lp: %5d %s\n", $i +, $first_pointer[$i], $last_pointer[$i], $the_dir[$i]); }
      something like
      for($i = 0; $i <= $last_dir; $i++) { @{$data[i]}(qw(deleted_file void the_dir first_pointer las +t_pointer has_subdir has_iden)) = split (/\"\|/, $tmp_2[$i], 7); #printf ("sort_dirs_debug2: %5d fp: %5d, lp: %5d %s\n", $i +, $first_pointer[$i], $last_pointer[$i], $the_dir[$i]); }
      or
      for($i = 0; $i <= $last_dir; $i++) { ($data[i]{deleted_file}, $void, $data[i]{the_dir}, $data[i]{first_po +inter}, $data[i]{last_pointer}, $data[i]{has_subdir}, $data[i]{has_iden}) = split (/\"\|/, $tmp_2[$i], 7); #printf ("sort_dirs_debug2: %5d fp: %5d, lp: %5d %s\n", $i +, $first_pointer[$i], $last_pointer[$i], $the_dir[$i]); }

      Jenda
      Enoch was right!
      Enjoy the last years of Rome.

      tmp_7 seems to be a typo. It should have been declared with the others.

      I am putting on my thinking cap. I am going to re-write this to be more efficient with memory. I have already made it more memory efficient (A little more) and now it doesn't crash (i.e. run out of memory, if that is in fact what's happening). I need to learn how to use hash tables (if that's even the correct term). I think it's time.

      Just so ya-all know where I was coming from, I thought using temp variables would allow me to get memory back after I was done with them. (i.e. undef @tmp_1). Yes I know, peek memory would still be an issue. If anyone wants to give me some guidance on how to go about re-writing this I would accept it.

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others pondering the Monastery: (7)
As of 2024-03-29 15:10 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found