Friday, June 22, 2012

How to read Perl command-line arguments | Perl command line args example/tutorial | devdaily.com

How to read Perl command-line arguments | Perl command line args example/tutorial | devdaily.com:

(even deadlier simple approach is noted at the end - ed).

How to read Perl command-line arguments

Perl FAQ: How do I read command-line arguments in Perl (i.e., "Perl command line args")?
If you want to handle simple Perl command line arguments, such as filenames and strings, this tutorial is for you. If you want to handle command-line options (flags) in your Perl scripts (like "-h" or "--help"), this new Perl getopts command line options/flags tutorial is what you need.

Perl command line args and the @ARGV array

With Perl, command-line arguments are stored in a special array named @ARGV. So you just need to read from that array to access your script's command-line arguments.
ARGV array elements: In the ARGV array, $ARGV[0] contains the first argument,$ARGV[1] contains the second argument, etc. So if you're just looking for one command line argument you can test for  $ARGV[0], and if you're looking for two you can also test for $ARGV[1], and so on.
ARGV array size: The variable $#ARGV is the subscript of the last element of the @ARGVarray, and because the array is zero-based, the number of arguments given on the command line is $#ARGV + 1.

Example 1: A typical Perl command line args example

A typical Perl script that uses command-line arguments will (a) test for the number of command line arguments the user supplied and then (b) attempt to use them. Here's a simple Perl script named "name.pl" that expects to see two command-line arguments, a person's first name and last name, and then prints them:
#!/usr/bin/perl -w

# (1) quit unless we have the correct number of command-line args
$num_args = $#ARGV + 1;
if ($num_args != 2) {
  print "\nUsage: name.pl first_name last_name\n";
  exit;
}

# (2) we got two command line args, so assume they are the
# first name and last name
$first_name=$ARGV[0];
$last_name=$ARGV[1];

print "Hello, $first_name $last_name\n";
This is fairly straightforward, where adding 1 to $#ARGV strikes me as the only really unusual thing.
To test this script on a Unix/Linux system, just create a file named name.pl, then issue this command to make the script executable:
chmod +x name.pl
Then run the script like this:
./name.pl Alvin Alexander
Or, if you want to see the usage statement, run the script without any command line arguments, like this:
./name.pl

Example 2: Perl command line arguments in a for loop

For a second example, here's how you might work through the command line arguments using a Perl for loop:
#!/usr/bin/perl
#---------------------#
#  PROGRAM:  argv.pl  #
#---------------------#

$numArgs = $#ARGV + 1;
print "thanks, you gave me $numArgs command-line arguments:\n";

foreach $argnum (0 .. $#ARGV) {
  print "$ARGV[$argnum]\n";
}

Running the example Perl command line program

To demonstrate how this works, if you run this Perl command line args program from a Unix command-line like this:
./argv.pl 1 2 3 4
or, from a DOS command-line like this
perl argv.pl 1 2 3 4
you'll get this result:
thanks, you gave me 4 command-line arguments:
1
2
3
4
As you can see, it prints all the command line arguments you supply to the Perl program.

------------------------------------------------------------------------------------------------------------
(or, an even simpler approach if you want it:
http://stein.cshl.org/genome_informatics/perl_intro/command_line.html

Processing Command Line Arguments

When a Perl script is run, its command-line arguments (if any) are stored in an automatic array called @ARGV. You'll learn how to manipulate this array later. For now, just know that you can call the shift function repeatedly from the main part of the script to retrieve the command line arguments one by one.

Printing the Command Line Argument

Code:
  
  #!/usr/bin/perl
  # file: echo.pl

  $argument = shift;
  print "The first argument was $argument.\n";
)

'via Blog this'

IEEE: Hidden Job Market Secrets: How to Make a New Job Fall into Your Lap

Hidden Job Market Secrets: How to Make a New Job Fall into Your Lap:


How to Make a New Job Fall into Your Lap
BY DEBRA FELDMAN, JOBWHIZ, EXECUTIVE TALENT AGENT
Many earnest job seekers end up feeling hopeless that they will ever find a new opportunity, let alone have a new job find them. They’ve submitted countless resumes, told everyone within earshot that they need a new job, been in touch with every recruiter they can think of, and have been doing what they believe is networking.  But, still, they remain no closer to an offer.  After a while, they run out of ideas and energy. A new position feels like an impossible situation.  But giving up, complaining or having a pity party won't change anything. It’s no wonder they are discouraged; but are they doing what it takes to be a competitive candidate and win an offer in today’s tough job market?
If this scenario sounds all-too familiar, don't despair. By making some subtle changes to your job search tactics, you can get back on track and position yourself as a go-to, in-demand expert in your field.
The surest way to improve your odds of getting an offer is to capture key decision-makers’ attention and then further convince the hiring manager that you are the best choice available. Sounds simple. But how do you do it? The best way to get the attention of decision-makers and hiring managers is to network purposefully. By networking purposefully, I mean emphasizing connections over job vacancies, and opportunities over HR requirements. Focus on building relationships based on trust and mutual professional interests, and the opportunities will come. If you build a network of connections, you will be privy to opportunities before you are even looking — and, more importantly, before other job seekers find out about them. Those are the jobs — also know as the hidden job market — where most of today's hiring takes place.
Networking purposefully means being in the right place at the right time. Getting there isn't always easy, but if you combine the right job search strategy with effective and efficient tactics, your chances of success will improve dramatically. Following are eight steps to help you start building your network in a purposeful and strategic way:
1.       Focus: Know what you do, what you want to do and how you produce results.
2.      Package: Describe your unique skills, talents, knowledge, know-how (i.e., your unique value contribution) in easy-to-understand terms that can be passed along in a recommendation.
3.      Target: Be clear and specific about what you are looking for so that when anyone has a “golden needle” they recognize that you are a good fit.
4.      Clarify: Your elevator pitch (i.e., your verbal resume), written marketing documents and online profile ( LinkedIn, author bio, byline, etc.) should be simple, concise and consistent, and must compellingly communicate the message you want others to understand, remember and pass along.
5.      Refine: Don’t try to be something for everyone to get any job. (This only results in being nothing to anyone!)
6.      Connect:  Limit the amount of time you spend applying to online postings; instead, devote the better part of your job search efforts to sourcing job leads directly (interacting and exchanging ideas with a human being!) by talking to prospective employers, including hiring authorities and target company employees, not HR or external recruiters, who can recommend you to key decision-makers within their respective organization or introduce you to others in their own network.
7.      Identify: Target top-choice employers and concentrate on making inside contacts, sharing mutual interests, gaining trust and developing relationships through research, recommendations and observing industry trends.
8.      Repeat: Continuously find and cultivate meaningful discussions with new contacts, while introducing those in your network to each other, sharing leads and ideas. These and similar exchanges not only reinforce your value, but deepen mutual feeling of trust and keep you top of mind for more networking referrals—whether or not you are actively in the job market or just want to keep in touch and know what is going on in your field.
If you already have the right insider contacts, you won't need to start from scratch establishing relationships. If you have connections but they aren't producing job leads, it means that one of the above steps is not working as it should be and needs to be fine tuned.  All of the above activities are designed to generate leads and make you among the first, if not the first, to know about  positions in the hidden job market.
You can give yourself a competitive advantage by being connected where the type of career opportunities you want can happen from time to time. Networking is a proven way to find a job.  Contacts can recommend you to a hiring authority, refer you so that you can start be among the first to express an interest, and help you to make the right connections before a job is advertised. 
What many people don’t know or forget about  networking is that it is a two-way process.  You can and should share any leads you have at a given moment (or those you get in the future) with your connections, who will return the favor in kind. If a potentially attractive opportunity comes your way, you can volunteer to be the first one outside the immediate group to get involved — well before a role is formally identified and anyone else throws their hat into the ring.  It happens more than you'd think. A new position might be created just for you, a role specifically well-suited to your specifications and which also matches the employer’s “ideal” requirements, too. By having the right connections, you will be well-positioned to learn early and often about impending reorganizations, unexpected departures, unplanned vacancies, etc., all of which produce prime openings in the hidden job market.
All Rights Reserved by Debra Feldman 2012. Reprinted with permission.
 
Comments on this story may be emailed directly to Today's Engineer or submitted through our online form.
 

Debra Feldman, founder of JobWhiz, is an executive talent agent with more than 20 years of senior management consulting experience. She uses networking to identify and connect candidates with unadvertised new career opportunities in the hidden job market. For more information or to email Debra visit JobWhiz.com.  Follow @Debra_Feldman or JobWhiz on Facebook.
  home


'via Blog this'

Thursday, June 21, 2012

Re: Principle Engineer: Auugggh! Fix It! No such title!

[Now it's 8,500 !  Aughhhh!!!!]
What it says to me when I see "Principle Engineer" on a resume:
"Not only am I an engineer that cannot spell, I also cannot spell even when it truly matters"   :-)

6,300 People in my LInkedIn network *can* be wrong... (you might see fewer):

prin·ci·ple/ˈprinsəpəl/Noun

1. A fundamental truth or proposition that serves as the foundation for a system of belief or behavior or for a chain of reasoning.
2. A rule or belief governing one's personal behavior.

Another Public Service Announcement from 
Connie L. O'Dell 
Principal Engineer and Spelling ****
c.odell@co-consulting.net 
303-641-5191 
_____________________________________________ 
CO Consulting - Boulder, CO - http://co-consulting.net


Friday, June 15, 2012

How to make calculations on hexadecimal numbers with awk? - Stack Overflow

hex - How to make calculations on hexadecimal numbers with awk? - Stack Overflow


I have a file containing a list of hexadecimal numbers, as 0x12345678 one per line.
I want to make a calculation on them. For this, I thought of using awk. But if printing an hexadecimal number with awk is easy with the printf function, I haven't find a way to interpret the hexadecimal input other than as text (or 0, conversion to integer stops on the x).
awk '{ print $1; }'                     // 0x12345678
awk '{ printf("%x\n", $1)}'             // 0
awk '{ printf("%x\n", $1+1)}'           // 1                 // DarkDust answer
awk '{ printf("%s: %x\n", $1, $1)}'     // 0x12345678: 0
Is it possible to print, e.g. the value +1?
awk '{ printf(%x\n", ??????)}'          // 0x12345679
Edit: One liners on other languages welcomed! (if reasonable length ;-) )
link|edit

feedback

3 Answers


In the original nawk and mawk implementations the hexadecimal (and octal) numbers are recognised.gawk (which I guess you are using) has the feature/bug of not doing this. It has a command line switch to get the behaviour you want: --non-decimal-data.
echo 0x12345678 | mawk '{ printf "%s: %x\n", $1, $1 }'
0x12345678: 12345678

echo 0x12345678 | gawk '{ printf "%s: %x\n", $1, $1 }'
0x12345678: 0

echo 0x12345678 | gawk --non-decimal-data '{ printf "%s: %x\n", $1, $1 }'
0x12345678: 12345678
link|edit
feedback

gawk has the strtonum function:
% echo 0x12345678 | gawk '{ printf "%s: %x - %x\n", $1, $1, strtonum($1) }'
0x12345678: 0 - 12345678
link|edit
feedback

You can convert the string into a number, simply by doing $1 + 0. AWK automagically converts a string to a number as needed. So you can do:
awk '{ printf "%X\n", $1+1; }'
or if you want 0x1234 notation:
awk '{ printf "0x%X\n", $1+1; }'
link|edit
This does not work on my Linux system (debian): It prints 1. My guess is that awk tries to interpret the value as decimal and stops right after the 0, on the x, ignoring that 0x is an hexadecimal notation prefix. – Didier Trosset Sep 10 '10 at 8:27
Was this post useful to you?     


'via Blog this'