02-19-2013
Welcome!
This forum has very strict rules, either you are a student in a school /college / univ etc as so you are to complete ALL the template, if you want to see you post accepted here or you are a IT user ( or not...) willing to learn or study from books in which case you can post in the adequate forum which would be programming but we cannot accept unclear situations sorry
So repost again accordingly
All the best
This User Gave Thanks to vbe For This Post:
10 More Discussions You Might Find Interesting
1. Shell Programming and Scripting
Bash : how do i check the user input and make sure is only character or only number ? (7 Replies)
Discussion started by: CheeSen
7 Replies
2. Shell Programming and Scripting
Hi guys,
Pretty new to regex, and i know im doing something wrong here. I'm trying to get a regex command that restricts a string to be 8 characters long, and the first character cannot be 0. Here's what i have so far...
echo "01234" | grep "^{8}*$"
Thanks very much!
-Crawf
... (7 Replies)
Discussion started by: crawf
7 Replies
3. UNIX for Dummies Questions & Answers
Hello everybody!!!
I am writing my own rm command in unix.
I prompt the user to type if he wants to delete a file and then read what he typed.
But how do i check what he typed?
This is my program so far:
echo 'Delete prog1.c (y/n)?'
read yesOrNo
if yesOrNo == 'y'
then
rm prog1.c... (6 Replies)
Discussion started by: mskart
6 Replies
4. Shell Programming and Scripting
Hi
I have one thing I need advice on, and I don't know where to start so I have no sample code.
I want the user to provide input like: 1-3,6,7,9-11
When the input is like this, I want a string to be generated including all the numbers. In the example above, the string would look like:
1... (13 Replies)
Discussion started by: Tobbev
13 Replies
5. Shell Programming and Scripting
Hi,
I need my script to check if the user enters 3 values if not 5 values to my script and alert if the input has any other number of values.
for example:
./myscript.sh 22 56 3221 - > correct
./myscript.sh 22 56 3221 45 777 -> correct
./myscript.sh 22 56 3221 45 -> incorrect
Please... (6 Replies)
Discussion started by: mohtashims
6 Replies
6. Shell Programming and Scripting
Hi,
On my Java webpage which invokes the shell script has two checkboxes viz ...
apache
and
weblogic
apache require one parameter i.e apache home from the user while Weblogic requires three or five params from the user vi.z weblogic_home or <jdk_home, config_home & pid>, username and... (4 Replies)
Discussion started by: mohtashims
4 Replies
7. Shell Programming and Scripting
How to check the user input to be valid using shell script?
The valid input is in the format like as follows.
1. It can only have r,w,x or a hyphen and nothing else.
2. ensure the r, w, x are in the correct order.
for example: rwxr-xr-x is a valid format.
Thanks (5 Replies)
Discussion started by: hyeewang
5 Replies
8. Shell Programming and Scripting
I am trying to create a bash script that will create new function by using the user input. The below will create the necessary files in the correct format, however when it comes to the # create function I am at a loss.
If the name entered was NEWNAME and the genes were GENE1,GENE2 then two files... (0 Replies)
Discussion started by: cmccabe
0 Replies
9. Shell Programming and Scripting
i am having file like this
#!/bin/bash
read -p 'Username: ' uservar
match='<color="red" />'
text='this is only a test
so please be patient
<color="red" />'
echo "$text" | sed "s/$match/&$uservar\g"
so desireble output what i want is if user type MARIA
this is only a test
so please... (13 Replies)
Discussion started by: tomislav91
13 Replies
10. Shell Programming and Scripting
Hi All,
#!/bin/bash
#Just trying to check if letters are in the user input. Any tips?
# I have tried regexp and using 0-9 etc, i cannot get this to work either in just an if statement or while in a loop.
echo "Please pick a number"
read num
if ; then
echo "Please enter a number"... (7 Replies)
Discussion started by: jvezinat
7 Replies
LEARN ABOUT DEBIAN
string::formatter::cookbook
String::Formatter::Cookbook(3pm) User Contributed Perl Documentation String::Formatter::Cookbook(3pm)
NAME
String::Formatter::Cookbook - ways to put String::Formatter to use
VERSION
version 0.102082
OVERVIEW
String::Formatter is a pretty simple system for building formatting routines, but it can be hard to get started without an idea of the sort
of things that are possible.
BASIC RECIPES
constants only
The simplest stringf interface you can provide is one that just formats constant strings, allowing the user to put them inside other fixed
strings with alignment:
use String::Formatter stringf => {
input_processor => 'forbid_input',
codes => {
a => 'apples',
b => 'bananas',
w => 'watermelon',
},
};
print stringf('I eat %a and %b but never %w.');
# Output:
# I eat apples and bananas but never watermelon.
If the user tries to parameterize the string by passing arguments after the format string, an exception will be raised.
sprintf-like conversions
Another common pattern is to create a routine that behaves like Perl's "sprintf", but with a different set of conversion routines. (It
will also almost ceratinly have much simpler semantics than Perl's wildly complex behavior.)
use String::Formatter stringf => {
codes => {
s => sub { $_ }, # string itself
l => sub { length }, # length of input string
e => sub { /[^x00-x7F]/ ? '8bit' : '7bit' }, # ascii-safeness
},
};
print stringf(
"My name is %s. I am about %l feet tall. I use an %e alphabet.
",
'Ricardo',
'ffffff',
'abcchdefghijklmnn~opqrrrstuvwxyz',
);
# Output:
# My name is Ricardo. I am about 6 feet tall. I use an 8bit alphabet.
Warning: The behavior of positional string replacement when the conversion codes mix constant strings and code references is currently
poorly nailed-down. Do not rely on it yet.
named conversions
This recipe acts a bit like Python's format operator when given a dictionary. Rather than matching format code position with input
ordering, inputs can be chosen by name.
use String::Formatter stringf => {
input_processor => 'require_named_input',
string_replacer => 'named_replace',
codes => {
s => sub { $_ }, # string itself
l => sub { length }, # length of input string
e => sub { /[^x00-x7F]/ ? '8bit' : '7bit' }, # ascii-safeness
},
};
print stringf(
"My %{which}s name is %{name}s. My name is %{name}l letters long.",
{
which => 'first',
name => 'Marvin',
},
);
# Output:
# My first name is Marvin. My name is 6 letters long.
Because this is a useful recipe, there is a shorthand for it:
use String::Formatter named_stringf => {
codes => {
s => sub { $_ }, # string itself
l => sub { length }, # length of input string
e => sub { /[^x00-x7F]/ ? '8bit' : '7bit' }, # ascii-safeness
},
};
method calls
Some objects provide methods to stringify them flexibly. For example, many objects that represent timestamps allow you to call "strftime"
or something similar. The "method_replace" string replacer comes in handy here:
use String::Formatter stringf => {
input_processor => 'require_single_input',
string_replacer => 'method_replace',
codes => {
f => 'strftime',
c => 'format_cldr',
s => sub { "$_[0]" },
},
};
print stringf(
"%{%Y-%m-%d}f is also %{yyyy-MM-dd}c. Default string is %s.",
DateTime->now,
);
# Output:
# 2009-11-17 is also 2009-11-17. Default string is 2009-11-17T15:35:11.
This recipe is available as the export "method_stringf":
use String::Formatter method_stringf => {
codes => {
f => 'strftime',
c => 'format_cldr',
s => sub { "$_[0]" },
},
};
You can easily use this to implement an actual stringf-like method:
package MyClass;
use String::Formatter method_stringf => {
-as => '_stringf',
codes => {
f => 'strftime',
c => 'format_cldr',
s => sub { "$_[0]" },
},
};
sub format {
my ($self, $format) = @_;
return _stringf($format, $self);
}
AUTHORS
o Ricardo Signes <rjbs@cpan.org>
o Darren Chamberlain <darren@cpan.org>
COPYRIGHT AND LICENSE
This software is Copyright (c) 2010 by Ricardo Signes <rjbs@cpan.org>.
This is free software, licensed under:
The GNU General Public License, Version 2, June 1991
perl v5.10.1 2010-10-19 String::Formatter::Cookbook(3pm)