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.
Well I think the first suggestion would be to either seek help from your manager if they have told you Perl is the only option and you clearly know nothing about it or if you would
like to learn more yourself and figure it out, I would suggest you google for how to read a file line by line in Perl and go from there.
grail, buddy, i don't know who are you, i don't care who are you, i dont\t know what you know, but I know something for sure, if you have some knowledges and "willing to help" someoone at least you can give some hint.
Now, i'm just trying to be polite... and if you don't understand my question I can can explain to you once more, or even i can draw.
the problem is you gave almost no information, you just want to have a solution.
You ought to read the guidelines of this forum. We won't write you this program, but will gladly help you to complete it. So please show what you have already....
Otherwise the best hint we can give you is just google, there are a lot of examples around there about how to read a file line by line and check the lines if they matches...
please use [code]here comes your code[/code] to keep formatting.
Also you can use variables in your script, to "remember" things. So you can set for example a variable $found if something was found and add lines at the end if $found is still zero (or undefined)
But I do not really understand what do you want to achieve
I think I've managed to do it
...
but let's say I do already have these line with definition, Now i just want to add deffinition3, deffinition4, etc...
Not sure if what you wrote serves your original intent, however you say it does. Therefore good.
That last addition is what I call "feature creep", because now it sounds as if instead of your original request where you detect a line with <resources> and then a following line with <script, you're now saying that if you have these <definition1 and <definition2 terms, in that case you now wish to add terms for <definition3 and <definition4.
The first overall problem is that you stated a problem and did not show your script, thereby making it difficult for someone to help you properly.
Now at this point you've added to the requirements, or you've created confusion because it's difficult to determine what criteria you are looking for and what possible results you are looking to attain.
What would help is if you were to examine the total requirements and summarize them better.
Obviously what further helps if when you post your script or code along with the problem description so that people who understand the particular language can offer their assistance.
my $filename = shift or die "Usage: $0 filename\n";
open my $fh, '<', $filename or die "Could not open '$filename' $!";
while (my $line = <$fh>) {
next if $line =~ /^\#/ || !$line; #skip blanks && commented
if ($line =~ /^\[(.*)\]\s*$/) {
$section = $1;
next;
}
if ($line =~ /^([^=]+?)\s*=\s*(.*?)\s*$/) {
my ($field, $value) = ($1, $2);
if (not defined $section) {
warn "Line outside of seciton '$line'\n";
next;
}
$data{$section}{$field} = $value;
}
}
open (my $fhIn, '<', 'cl.xml') or die $!;
open (my $fhOut, '>', 'cl.xml.new') or die $!;
while (<$fhIn>) {
foreach my $se (sort keys data) {
foreach my $param (sort keys {$data{$se}}) {
my $mp=$data{$se}->{$param};
if (/<resources>/){
last;
}
if (/script file/) {print $fhOut "\t\t\t<vgfs=$se/${mp}\" >\"/>\n" if /script file/;
} else { print $fhOut "\t\t\t<lvgfs=$se/${se}_$num\"/>\n" if /lv01_001/; }
}
}
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.