Hi,
Would like to learn and know how to sort the ip address using perl script?
For example:
172.27.32.200
172.19.32.100
10.1.1.60
192.20.30.133
@ipaddress = ('172.27.32.200 ','10.1.1.60',' 192.20.30.133', '172.19.32.100' );
Don't know what to do next?
thanks,
Ken
4 10248 miller 1,089
Recognized Expert Top Contributor
Hello Ken,
There are likely lots of different ways to accomplish this, but here is one that I think is particularly cute. -
my @ips = qw(
-
172.27.32.200
-
172.19.32.100
-
10.1.1.60
-
192.20.30.133
-
);
-
-
@ips = map {s/\s+//g; $_} sort map {s/(\d+)/sprintf "%3s", $1/eg; $_} @ips;
-
-
print join "\n", @ips;
-
-
# Output is:
-
# 10.1.1.60
-
# 172.19.32.100
-
# 172.27.32.200
-
# 192.20.30.133
-
- Miller
Thanks Miller. This is excellent example
Thanks
Hello Ken,
we can do many ways so here is to sort based on numeric
sort is by default based on strings but if you want to sort based on number in perl
syntax:sort{$a <=>$b} - @ipaddress = ('172.27.32.200','10.1.1.60','192.20.30.133','172. 19.32.100');
-
@ips=sort{$a<=>$b}(@ipaddress);
-
foreach (@ips)
-
{
-
print "$_\n";
-
}
HI Miller,
May I know what does
means here. - {s/(\d+)/sprintf "%3s", $1/eg; $_}
Sign in to post your reply or Sign up for a free account.
Similar topics |
by: kelly |
last post by:
Hi,
I don't have a code to show you, what I need are references or
algorithms so that I'm in a right track.
By the way, thanks for introducing me the array or arrays. Now I can
continue my script.
Now I want to delete a line from a file. Line being the strings I
got/saved to/from array of arrays.
|
by: kraj123 |
last post by:
Hi Friends,
I would apprciate, if anyone could help me out regarding coding tips for writing a perl script for automating a snapshot process. Snapshot is nothing but capturingn forms from different language database local servers like russia,japan..which are in csv file taken as input and comparing with present english database forms in our system and output it as definition file. this out put should be checkin to repository....this should...
|
by: jram01 |
last post by:
Hi Folks,
I am facing problem to to execute .sql command in sql prompt using perl script. I am able to connect sql promt using "
my $odbcinput = "odbcinput.txt";
my $odbcoutput = "odbcoutput.txt";
open (ODBCSQLFH, ">$odbcinput") || die "Unable to create input file ($odbcinput) for odbcsql\n";
|
by: leierwu |
last post by:
1. I have a folder containing several files;
2. Now these files should be added a header with the file name in the first line;
How can I complish this using perl script?
|
by: jawas |
last post by:
Can any body help to write the general Perl script to transfer file from one window XP machine to another window XP machine and then change the file name and send some command for e.g config, 9,9 to run that file which we changed the name.
I really appreciate, I some one provide any sample Perl scipt in window enviorment.
Thanks
Jamal
| |
by: jyo123 |
last post by:
Hi,
Is there any way to write perl script to save the popup window into specified location.Please anyone help on this.
Thanks is advance.
|
by: gajendra98 |
last post by:
Hi
I am working on windows .....IS it possible to block the remote computer python plug-ins using perl script...could some one tell me how to perform these operations.....Thanks
|
by: flow3rgirlz |
last post by:
Hi all,
I'm really new to Perl. I'm not sure where to post my topic as it between Perl and Visio. Anyway, I want to run a Visio macro automatically using Perl Script.
$vis->Run($macro_to_run);
I found this method to run in Word macro. I tried to use this macro in Word and it works. But when i use in Visio macro, it doesnt run the macro. Is there any different way to run Visio macro in Perl?
|
by: sree ram |
last post by:
code for getting maximum rows in excel sheet using perl script
|
by: marktang |
last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look !
Part I. Meaning of...
|
by: Hystou |
last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it.
First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
| |
by: Oralloy |
last post by:
Hello folks,
I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>".
The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed.
This is as boiled down as I can make it.
Here is my compilation command:
g++-12 -std=c++20 -Wnarrowing bit_field.cpp
Here is the code in...
|
by: jinu1996 |
last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth.
The Art of Business Website Design
Your website is...
|
by: Hystou |
last post by:
Overview:
Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
|
by: tracyyun |
last post by:
Dear forum friends,
With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
|
by: isladogs |
last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM).
In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules.
He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms.
Adolph will...
|
by: conductexam |
last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one.
At the time of converting from word file to html my equations which are in the word document file was convert into image.
Globals.ThisAddIn.Application.ActiveDocument.Select();...
| |
by: adsilva |
last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
| |