Ik ben nog niet zo ervaren met Perl, dus wellicht is het een makkelijke vraag, maar ik kan het in de boeken die ik hier heb liggen en google enzo niet vinden...
Situatie:
Onderste stuk is een deel uit het totale script. In $file komt bv ./dir_name/subdir/bla.txt. Met check_dir wil ik kijken of dir_name (of subdir) al in $directory staat. Wat ik dus doe is de hash meegeven naar de subroutine en ook de huidige dir die ie behandelt (dus bv 'subdir').
Wat gaat er fout:
De hash komt goed binnen, maar search_string is leeg. Dit terwijl ik 'm print (stuk met before:), en het daar wel goed is. Waarschijnlijk is het dus iets met het doorgeven van die variable naar de subroutine, maar hoe of wat ik het moet doen is mij onduidelijk. Ik heb al combinaties verzonnen met \ of *, maar blijkbaar wil dat niet.
Melding die ik nu krijg:
Use of uninitialized value in concatenation (.) or string at line 11.
Situatie:
Perl:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
| # this function checks if the directory is already set in the hash sub check_dir { # get the required variables; my (%directories, $search_dir) = @_; my $index; foreach $index (keys %directories) { printf('dirindex: '.$directories{$index}."\n"); printf('search: '.$search_dir."\n"); if ($directories{$index} eq $search_dir) { printf("Is in array!\n"); } } } # split the path into directories and files @path = split(/\//, $file); # walk through the path for ($i = 0; $i < @path; $i++) { # handle the parent dir if (($i == 1) and ($i < @path - 1)) { printf("\n___handle______\n"); $directory{$id}{'id'} = $id; $directory{$id}{'name'} = $path[$i]; $directory{$id}{'subdir'} = 0; $id++; printf('before: '.$path[$i]."\n"); check_dir(\%directory,$path[$i]); } # handle the subdir elsif ($i > 1 and $i < @path - 1 and 0) { $directory{$id}{'id'} = $id; $directory{$id}{'name'} = $path[$i]; $directory{$id}{'subdir'} = 1; $directory{$id}{'parent'} = $path[$i - 1]; $id++; printf('before: '.$path[$i]."\n"); check_dir(\%directory,$path[$i]); } } |
Onderste stuk is een deel uit het totale script. In $file komt bv ./dir_name/subdir/bla.txt. Met check_dir wil ik kijken of dir_name (of subdir) al in $directory staat. Wat ik dus doe is de hash meegeven naar de subroutine en ook de huidige dir die ie behandelt (dus bv 'subdir').
Wat gaat er fout:
De hash komt goed binnen, maar search_string is leeg. Dit terwijl ik 'm print (stuk met before:), en het daar wel goed is. Waarschijnlijk is het dus iets met het doorgeven van die variable naar de subroutine, maar hoe of wat ik het moet doen is mij onduidelijk. Ik heb al combinaties verzonnen met \ of *, maar blijkbaar wil dat niet.
Melding die ik nu krijg:
Use of uninitialized value in concatenation (.) or string at line 11.
Ook Knor is aangestoken met het ligfietsvirus!