ProgrammingThis forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.
Notices
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
hi all,
I'm writing this two code snippets and need suggestion about that.
1) So, how I can print line wich contained into $x?
Code:
#!/usr/bin/perl
use diagnostics;
use strict;
my @file= <DATA>;
my $str = join( '', @file);
my $x = '/dev/sda1';
if($str =~ /Mounted\s+on(.*?)/sgi ){
my @s = join '', $1;
print grep(/$x/,@s);
}
__DATA__
Filesystem 1K-blocks Used Available Use% Mounted on
/dev/sda3 487730816 484563176 3167640 100% /
/dev/sda1 248895 138484 97561 59% /boot
/dev/sdb1 488252928 314127712 174125216 65% /mnt/s
/dev/sdc1 15674912 14776312 898600 95% /media/disk-2
2) and there...
If I to enroll values to 'a' and 'b' and in the next I need use foreach and evaluate either value from either key. When that set key 'a' it should be evaluate 1 and second if that need. Second and other values should be use only if use of first was destroyed. Actually I need perl-tecnics how that make.
my $z;
foreach(%h){
my $w =$_;
foreach(@{$h{$w}}){
my @a;
$z=$_;
nextvalue:
if(grep(/$h{$z}/i,@a)){
}else{
if(destroyer($z)){
...work..
}else{
foreach (@{$h{$_}}){
$lz=$_;
if($lz ne $z){
goto nextvalue;
}
}
}
push(@a,"$w\n"); # so as not get it twice
}
}
}
sub destroyer(){
if(...smth...){
return 0;
}else{
return 1;
}
}
unfortunaly, the some keys can use twice several values and then I've got not true result.
Can everyone please both put code into [code][/code] tags and indent the code properly? It's very hard to read something longer than a few lines with zero indentation.
@Umbrella - if you know that the keys are not unique, then a hash may not be your best option. Hash keys must be unique. You probably need to use a different data structure. Edit: Actually, now that I look at your first post again, I realize that I have nearly no idea what you are actually trying to do. Can you please explain it more clearly?
Last edited by Telemachos; 07-03-2009 at 06:41 AM.
I'm gave code snippet which kind of works, but not for everyone key. So, if $z missed, then func destroyer return zero and main while should go to the next value in 'a'(which's not equal other pasted values in there) and so on... until destroyer returned 1. And if destroyer returned 1 in first value that's good and it enough for 'a'. Because I need do work everyone key, but if value in that key was true.
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.