Leser: 1
10 Einträge, 1 Seite |
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
use Tie::File;
my $flat_file = '/path/to/flat.file';
tie my @array, 'Tie::File',$flat_file or die $!;
my $index = grep{$_->[0] =~ /^$id_from_form\*\*/}@array;
if($move eq 'up'){
my $elem = $array[$index];
$array[$index] = $array[$index-1];
$array[$index-1] = $elem;
}
else{
my $elem = $array[$index];
$array[$index] = $array[$index+1];
$array[$index-1] = $elem;
}
untie @array;
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
use Tie::File;
my $id_from_form=3;
my $move="up";
my $flat_file = 'path/to/flat.file';
tie my @array, 'Tie::File',$flat_file or die $!;
my $index = grep{$_->[0] =~ /^$id_from_form\*\*/}@array;
if($move eq 'up'){
my $elem = $array[$index];
$array[$index] = $array[$index-1];
$array[$index-1] = $elem;
}
else{
my $elem = $array[$index];
$array[$index] = $array[$index+1];
$array[$index-1] = $elem;
}
untie @array;
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
use Tie::File;
my $id_from_form=3;
my $move="up";
my $flat_file = 'path/to/flat.file';
tie my @array, 'Tie::File',$flat_file or die $!;
my $index = grep{$_->[0] =~ /^$id_from_form\*\*/}@array;
if($move eq 'up'){
my $elem = $array[$index];
$array[$index] = $array[$index-1];
$array[$index-1] = $elem;
}
else{
my $elem = $array[$index];
$array[$index] = $array[$index+1];
$array[$index-1] = $elem;
}
untie @array;
grep{$_->[0]
grep{$_
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
#!/usr/bin/perl
use strict;
use warnings;
use Tie::File;
my $id_from_form=5;
my $move="up";
my $flat_file = './flat.file';
tie my @array, 'Tie::File',$flat_file or die $!;
chomp @array;
my ($index) = grep{$array[$_] =~ /^$id_from_form\*\*/}(0..$#array);
print $index,"\n";
if($move eq 'up'){
my $elem = $array[$index];
$array[$index] = $array[$index-1];
$array[$index-1] = $elem;
}
else{
my $elem = $array[$index];
$array[$index] = $array[$index+1];
$array[$index+1] = $elem;
}
$_ . "\n" for @array;
untie @array;
10 Einträge, 1 Seite |