Learnt an example of Lazy match in Regex in Perl, so thought to share here.
Let's say following is Input_file.
Now we would like to have data between first occurrence of ^ to DUMMY , then we could use Lazy match like as follows:
Output will be as follows for mentioned sample:
Why is Lazy match Good here? Because .* is a GREEDY match and matches anything till last occurrence of any mentioned character etc but using Lazy match .*?DUMMY\s+ it matches very first occurrence of string DUMMY followed with space starting from ^
Tested and written this in PERL, thought/views/improvements are most welcome here.
Thanks,
R. Singh
This User Gave Thanks to RavinderSingh13 For This Post:
can i do this? i am learning this on my own..and from the book..simple unix i am not sure if the syntax would work
if
statement
then
statement
do or for or while
statement
done
else
statement
fi....
I dont know how else to explain that...I hope I... (2 Replies)
I am having trouble parsing rpm filenames in a shell script.. I found a snippet of perl code that will perform the task but I really don't have time to rewrite the entire script in perl. I cannot for the life of me convert this code into something sed-friendly:
if ($rpm =~ /(*)-(*)-(*)\.(.*)/)... (1 Reply)
Folks! Anyone please explain the behavior of this program step by step. Thanks.
#! /usr/bin/perl
$testfile = "./testfile2";
for ( $i = 1, $i <= 5, $i++) {
open ($FILE, ">", $testfile);
print ($FILE "Output 1 \n");
close ($FILE);
}
print "The value of (4 * 2) / 2 is ";
print (4 * 2)... (1 Reply)
Hello Unix graduates,
I have gone through 50 posts here in this Unix.com, out of which 35-40 are answered with regex.. Regex is always been a problem for me. :wall:
I have gone through few URLs still it doesn't help me to reach what you guys are.. :confused:
How to get skilled on... (1 Reply)
I have a file of protein sequences with headers (my source file). Based on a list of IDs (which are included in some of the headers), I'd like to print out only the specified sequences, with only the ID as header.
In other words, I'd like to search source.txt for the terms in IDs.txt, and print... (3 Replies)
Hello All,
I am a beginner in C, although I believe my learning curve is rather steep.
I would like to know if any of you would have some recommendations with some learning materials to become a good C developer.
I am particularly thinking about some CBT courses or some good Quizz that would... (2 Replies)
I am not a big expert in regex and have just little understanding of that language.
Could you help me to understand the regular Perl expression:
^(?!if\b|else\b|while\b|)(?:+?\s+){1,6}(+\s*)\(*\) *?(?:^*;?+){0,10}\{
------
This is regex to select functions from a C/C++ source and defined in... (2 Replies)
I'm trying to get some exclusions into our sendmail regular expression for the K command. The following configuration & regex works:
LOCAL_CONFIG
#
Kcheckaddress regex -a@MATCH
+<@+?\.++?\.(us|info|to|br|bid|cn|ru)
LOCAL_RULESETS
SLocal_check_mail
# check address against various regex... (0 Replies)
Discussion started by: RobbieTheK
0 Replies
LEARN ABOUT DEBIAN
config::model::dumpasdata
Config::Model::DumpAsData(3pm) User Contributed Perl Documentation Config::Model::DumpAsData(3pm)NAME
Config::Model::DumpAsData - Dump configuration content as a perl data structure
VERSION
version 2.021
SYNOPSIS
use Config::Model ;
use Log::Log4perl qw(:easy) ;
use Data::Dumper ;
Log::Log4perl->easy_init($WARN);
# define configuration tree object
my $model = Config::Model->new ;
$model ->create_config_class (
name => "MyClass",
element => [
[qw/foo bar/] => {
type => 'leaf',
value_type => 'string'
},
baz => {
type => 'hash',
index_type => 'string' ,
cargo => {
type => 'leaf',
value_type => 'string',
},
},
],
) ;
my $inst = $model->instance(root_class_name => 'MyClass' );
my $root = $inst->config_root ;
# put some data in config tree the hard way
$root->fetch_element('foo')->store('yada') ;
$root->fetch_element('bar')->store('bla bla') ;
$root->fetch_element('baz')->fetch_with_id('en')->store('hello') ;
# put more data the easy way
my $step = 'baz:fr=bonjour baz:hr="dobar dan"';
$root->load( step => $step ) ;
print Dumper($root->dump_as_data);
# $VAR1 = {
# 'bar' => 'bla bla',
# 'baz' => {
# 'en' => 'hello',
# 'fr' => 'bonjour',
# 'hr' => 'dobar dan'
# },
# 'foo' => 'yada'
# };
DESCRIPTION
This module is used directly by Config::Model::Node to dump the content of a configuration tree in perl data structure.
The perl data structure is a hash of hash. Only CheckList content will be stored in an array ref.
Note that undefined values are skipped for list element. I.e. if a list element contains "('a',undef,'b')", the data structure will contain
'a','b'.
CONSTRUCTOR
new ( )
No parameter. The constructor should be used only by Config::Model::Node.
Methods
dump_as_data(...)
Return a perl data structure
Parameters are:
node
Reference to a Config::Model::Node object. Mandatory
full_dump
Also dump default values in the data structure. Useful if the dumped configuration data will be used by the application. (default is
yes)
skip_auto_write
Skip node that have a "perl write" capability in their model. See Config::Model::AutoRead.
auto_vivify
Scan and create data for nodes elements even if no actual data was stored in them. This may be useful to trap missing mandatory values.
ordered_hash_as_list
By default, ordered hash (i.e. the order of the keys are important) are dumped as Perl list. This is the faster way to dump such hashed
while keeping the key order. But it's the less readable way.
When this parameter is 1 (default), the ordered hash is dumped as a list:
[ A => 'foo', B => 'bar', C => 'baz' ]
When this parameter is set as 0, the ordered hash is dumped with a special key that specifies the order of keys. E.g.:
{ __order => [ 'A', 'B', 'C' ] ,
B => 'bar', A => 'foo', C => 'baz'
}
Methods
dump_annotations_as_pod(...)
Return a string formatted in pod (See perlpod) with the annotations.
Parameters are:
node
Reference to a Config::Model::Node object. Mandatory
experience
master, advanced or beginner
check_list
Yes, no or skip
AUTHOR
Dominique Dumont, (ddumont at cpan dot org)
SEE ALSO
Config::Model,Config::Model::Node,Config::Model::ObjTreeScanner
perl v5.14.2 2012-11-09 Config::Model::DumpAsData(3pm)